How to add commas to number every 3 digits in Objective C?

后端 未结 9 742

If I have a number int aNum = 2000000 how do I format this so that I can display it as the NSString 2,000,000?

9条回答
  •  青春惊慌失措
    2020-11-28 03:26

    Even easier:

    NSNumber *someNumber = @(1234567890);
    NSString *modelNumberString = [NSString localizedStringWithFormat:@"%@", someNumber];
    NSLog(@"Number with commas: %@", modelNumberString);
    

    coworker just taught me this today. #amazing

提交回复
热议问题