Got a big NSDecimal
with high precision. Like this:
NSString *decStr = @"999999999999.999999999999";
NSDecimal dec;
NSScanner *scanner = [[NSScanner alloc] initWithString:decStr];
[scanner scanDecimal:&dec];
NSDecimalNumber *decNum = [[NSDecimalNumber alloc] initWithDecimal:*dec];
I can easily get a string representation of my NSDecimal
with this:
NSString *output = [decNum stringValue];
Or
NSString *output = [decNum descriptionWithLocale:nil];
But it's never formatted correctly for output on screen:
output = 999999999999.999999999999
I want it to have group separation like 999,999,999,999.999999999999
So I tried a NSNumberFormatter
:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setAllowsFloats:YES];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setNumberStyle:kCFNumberFormatterDecimalStyle];
NSString *output = [formatter stringFromNumber:resultDecNum];
It ends up with this:
output = 1,000,000,000,000
Is there a way to get a big high precision NSDecimal
formatted correctly based on users locale without losing precision?