View Full Version : Converting floats to a String with commas
Jan 3, 2009, 09:38 AM
What's the best way to convert a any number to a string with commas?
so for instance:
int i = 1000000
will be printed as 1,000,000
Look for stringWithFormat.
Jan 3, 2009, 11:44 AM
I did, but I can't find a comma notation there, only scientific notation.
Since i use it seldom I cannot give you the entire info.
But the following is outside from one of my running programs.
The documentation under XCode Help is very good, as far as I remember.
[NSString localizedStringWithFormat:@"%1.1f%%", [[NSNumber numberWithFloat: 1011.213 ]
Jan 3, 2009, 05:09 PM
Look at NSNumberFormatter.
Jan 3, 2009, 05:43 PM
Just for other people who needs it, the specific command is:
(I added the $ sign to add the currency symbol).
Jan 3, 2009, 10:41 PM
for some reason when running the app on the device you get an error message when using setFormat.
numberFormatter = [[NSNumberFormatter alloc] init];