saman01
saman01

Reputation: 1004

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

Upvotes: 2

Views: 188

Answers (2)

EmptyStack
EmptyStack

Reputation: 51374

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".

Upvotes: 2

Paul.s
Paul.s

Reputation: 38728

Try this

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

or alternativly just print the NSNumber as an object

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

Upvotes: 9

Related Questions