开发者

nsmutablearray float object returns a zero

In the root model I have:

[self.rPrices replaceObjectAtIndex:0
                        withObject:[NSNumber numberWithFloat:(float)nR4]]; 
NSLog(@"%.2f", [self.rPrices objectAtIndex:0]);

where开发者_如何学编程 rPrices is NSMutableArray.

nR4 is not zero but the above NSLog(...); displays zero.

Thanks


Try this

NSLog(@"%.2f", [[self.rPrices objectAtIndex:0] floatValue]);

or alternativly just print the NSNumber as an object

NSLog(@"%@", [self.rPrices objectAtIndex:0]);


NSNumber is an object. So you can't print it using float format specifier "%f".

You can use "%@" or get the float value from it using -floatValue and print it using "%f".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜