2

I have a double value in Objective-C and I need to place its value into label. How should I format it into string with 2 decimal places after dot and with separators of thousands?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Metaller
  • 412
  • 3
  • 10

1 Answers1

3

Use NSNumberFormatter, for example:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setPositiveFormat:@"#,##0.00" ];

NSString *string = [formatter stringFromNumber:[ NSNumber numberWithDouble:1234567.8901 ] ];
// string is now "1,234,567.89"
[formatter release];
martin clayton
  • 74,574
  • 30
  • 214
  • 196