I can't seem to find an easy way to do it. The exact thing I need is:
[NSString stringWithFormat:@"%d doodads", n];
Where n is an int. So for 1234 I'd want this string (under my locale):
@"1,234 doodads"
Thanks.
I can't seem to find an easy way to do it. The exact thing I need is:
[NSString stringWithFormat:@"%d doodads", n];
Where n is an int. So for 1234 I'd want this string (under my locale):
@"1,234 doodads"
Thanks.
This was the only way I could make it work.
NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setFormat: @"#,###"];
NSString* doodads = [formatter stringFromNumber:[NSNumber numberWithInt:n]];
[formatter release];
The docs aren't clear if this is properly localised or not. I'm guessing no, it isn't, it will always use commas. Which sucks.
For 10.6 this works:
numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
NSString *numberString = [numberFormatter stringFromNumber: [NSNumber numberWithInteger: i]];
And it properly handles localization.