IOS:字符串的双值问题

IOS:字符串的双值问题,ios,xcode,double,Ios,Xcode,Double,我有这个密码 其中,我在数组数组中插入一个双精度值 double myDouble = [textField2.text doubleValue]; NSArray *temp = [[NSArray alloc]initWithObjects: textField1.text, [NSNumber numberWithDouble:myDouble], nil]; [appDelegate.extra addObject:temp]; 等我做完 NSString *cost = [NSStr

我有这个密码

其中,我在数组数组中插入一个双精度值

double myDouble = [textField2.text doubleValue];
NSArray *temp = [[NSArray alloc]initWithObjects: textField1.text, [NSNumber numberWithDouble:myDouble], nil];
[appDelegate.extra addObject:temp];
等我做完

NSString *cost = [NSString stringWithFormat: @"%.2f", [[appDelegate.extra objectAtIndex:0]objectAtIndex:1]];

[label1 setText:[[appDelegate.extra objectAtIndex:0]objectAtIndex:0]];
[label2 setText:cost];
那么,如果我在文本字段2中写“1”,那么在label2中就有“0.00”……为什么?

试试:

NSString *cost = [NSString stringWithFormat: @"%.2f", [[appDelegate.extra objectAtIndex:0]objectAtIndex:1] floatValue];