views:

44

answers:

0

I'm trying to get NSDecimalNumber to print out large numbers, 15 or more digits. At 15 digits I see 111,111,111,111,111. Above 15 digits I see 1,111,111,111,111,110 even though the number being formatted is 1111111111111111.

An example to illustrate my problem:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setMaximumSignificantDigits:25];
[formatter setUsesSignificantDigits:true];

NSDecimalNumber* test = [NSDecimalNumber decimalNumberWithString:@"12345678901234567890"];

NSString* output = [formatter stringFromNumber:test]; 
NSLog( @"num value: %@", test ); 
NSLog( @"str value: %@", output );

And the output looks like:

2010-09-16 09:24:16.783 SimpleCalc[739:207] num value: 12345678901234567890
2010-09-16 09:24:16.784 SimpleCalc[739:207] str value: 12,345,678,901,234,600,000

What silly thing have I missed?