在根模型中我有:
[self.rPrices replaceObjectAtIndex:0
withObject:[NSNumber numberWithFloat:(float)nR4]];
NSLog(@"%.2f", [self.rPrices objectAtIndex:0]);
其中rPrices为NSMutableArray
。
nR4不为零,但上述NSLog(...);
显示为零。
由于
答案 0 :(得分:9)
试试这个
NSLog(@"%.2f", [[self.rPrices objectAtIndex:0] floatValue]);
或者只是将NSNumber
打印为对象
NSLog(@"%@", [self.rPrices objectAtIndex:0]);
答案 1 :(得分:2)
NSNumber是一个对象。所以你不能使用浮点格式说明符“%f”打印它。
您可以使用“%@”或使用-floatValue
从中获取浮动值,然后使用“%f”打印。