I have an NSDecimalNumber
representing a money amount.
I want to print it as \"999 999 999 999 999 999,00\", regardless on the locale.
How do I do that?
Try this:
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"US"];
NSNumberFormatter *frm = [[NSNumberFormatter alloc] init];
[frm setNumberStyle:NSNumberFormatterDecimalStyle];
[frm setMaximumFractionDigits:2];
[frm setMinimumFractionDigits:2];
[frm setLocale:usLocale];
NSString *formattedNumberStr = [frm stringFromNumber:[NSNumber numberWithFloat:floatToRound]];
[frm release];
[usLocale release];
return formattedNumberStr;
I had the same problem. I was told that NSNumberFormatter
converts everything to a double
first. How did I solve it? It's easy, just write your own formatter.