I have a NSString which contains a very large number. I need to convert this to a NSNumber, but it’s always returning a NSNumber in scientific format, which isn’t good (I’m using the number in a predicate, to search for a music track with this MPMediaEntityPropertyPersistentID).
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *str = @"14881035034468747982";
DLog(@"before: %@", str);
NSNumber *nmb = [numberFormatter numberFromString:str];
DLog(@"after: %@", nmb);
Prints:
<AppDelegate.m:199> before: 14881035034468747982
<AppDelegate.m:201> after: 1.488103503446875e+19
If I use this number to search the iPod library, nothing is returned.
I’m afraid I was a bit too quick with asking this question. Once I figured out that the number in question is an unsigned long long, finding the answer wasn’t that hard.