If I have a number int aNum = 2000000
how do I format this so that I can display it as the NSString 2,000,000?
views:
744answers:
3
+5
A:
Don't do your own number formatting. You will almost certainly not get all the edge cases right or correctly handle all possible locales. Use the NSNumberFormatter
for formatting numeric data to a localized string representation.
You would use the NSNumberFormatter
instance method -setGroupingSeparator:
to set the grouping separator to @","
and -setGroupingSize:
to put a grouping separator every 3 digits.
Barry Wark
2010-02-10 01:39:08
Cool, am I all set after I -setGroupingSize: ? Or do I need to -setFormat: ?
RexOnRoids
2010-02-10 01:47:05
I also had to do [formatter setUsesGroupingSeparator:YES];
adam
2010-03-29 13:00:12
A:
What about the countless countries that don't use "," or "3 digit intervals"????
Susanna
2010-05-20 01:20:07