Reputation: 8111
NSNumber *abc = [[NSNumber alloc] initWithInt:123];
NSString *number = [NSString stringWithFormat:@"%d", abc];
The result of number
is 31619! How to fix it?
Upvotes: 0
Views: 741
Reputation: 11839
This is not an objective C bug, you are using wrong specifier-
Use -
NSString *number = [NSString stringWithFormat:@"%@", abc];
Upvotes: 4
Reputation: 7344
You have to return an intValue:
NSNumber *abc = [[NSNumber alloc] initWithInt:123];
NSString *number = [NSString stringWithFormat:@"%i", [abc intValue]];
Upvotes: 4