comma separated thousand NSString stringWithFormat

前端 未结 2 1930
闹比i
闹比i 2020-12-29 05:37

Is it possible to display 1000.99 as 1,000.99 using

[NSString stringWithFormat:@\"£%0.2f\", 1000.99]

Please guide me if I am not on the ri

相关标签:
2条回答
  • 2020-12-29 06:19

    Using NSNumberFormatter:

    NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat: 1000.99]];
    NSLog(@"%@", numberAsString);
    
    0 讨论(0)
  • 2020-12-29 06:21

    See NSNumberFormatter.

    It can handle all your numeric formatting needs and do so in an automatically localized fashion, when used correctly (since currencies around the world are often written with different punctuation & formatting).

    In particular, check out the number formatting guide linked to at the top of the class documentation

    0 讨论(0)
提交回复
热议问题