views:

744

answers:

3

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?

A: 

Check out NSNumberFormatter in the docs.

Squeegy
+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
Cool, am I all set after I -setGroupingSize: ? Or do I need to -setFormat: ?
RexOnRoids
I also had to do [formatter setUsesGroupingSeparator:YES];
adam
A: 

What about the countless countries that don't use "," or "3 digit intervals"????

Susanna