Elendas
Elendas

Reputation: 763

Console does not show me the right value while using NSLog to show a placeholder of an Array

I try to print the second placeholder of an Array in the console with the following code:

NSArray *europeTransaction = [[NSArray alloc] initWithObjects:europeDollarTransaction,  [NSNumber alloc] initWithDouble: 200.00], nil];    

NSLog(@"I'm displaying the second placeholders value in the NSArray %.2f", europeTransaction [1]);

The console shows me a value of 0.00, while it should give me a value of 200. What's wrong with the code?

Upvotes: 0

Views: 58

Answers (1)

DrummerB
DrummerB

Reputation: 40211

The format specifier %f is used for floats, while you are passing an NSNumber instance. Either use the specifier %@ or ask the NSNumber for its float representation:

NSLog(@"I'm displaying the second placeholders value in the NSArray %.2f",
      [europeTransaction[1] floatValue]);

Upvotes: 1

Related Questions