Easiest way to format a number with thousand separators to an NSString according to the Locale

后端 未结 5 1435
悲&欢浪女
悲&欢浪女 2020-12-09 02:45

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. S

5条回答
  •  渐次进展
    2020-12-09 03:16

    For 10.6 this works:

    NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
    NSString *numberString = [numberFormatter stringFromNumber: [NSNumber numberWithInteger: i]];
    

    And it properly handles localization.

提交回复
热议问题