3

I can't figure out why it's not working, I have a NSString which I need to convert to NSNumber (to save it to Core Data) e.g

NSLog(stringNum); 

returns 1

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *myNumber = [f numberFromString:stringNum];
[f release];

NSLog(@"myNumber = %i", myNumber); 

returns 120882496 or something like this

What am I missing? Thanks for help

Marcus S. Zarra
  • 46,571
  • 9
  • 101
  • 182
Burjua
  • 12,506
  • 27
  • 80
  • 111
  • possible duplicate of [How to convert an NSString into an NSNumber](http://stackoverflow.com/questions/1448804/how-to-convert-an-nsstring-into-an-nsnumber) – Björn Aug 09 '10 at 12:26
  • @Björn: This is obviously where he got the code from, but his problem is another one, namely the NSLog-error. – Pascal Aug 09 '10 at 12:33

2 Answers2

14

It's now an object, not an integer, therefore you must use %@ in NSLog, not %i.

Pascal
  • 16,846
  • 4
  • 60
  • 69
3

myNumber is an object, so the format should be

@"myNumber = %@"
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178