开发者

nsmutablearray float object returns a zero

开发者 https://www.devze.com 2023-03-19 06:15 出处:网络
In the root model I have: [self.rPrices replaceObjectAtIndex:0 withObject:[NSNumber numberWithFloat:(float)nR4]];

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

精彩评论

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