How to convert int to NSString?

后端 未结 4 1137
不思量自难忘°
不思量自难忘° 2020-11-27 12:42

I\'d like to convert an int to a NSString in Objective C.

How can I do this?

4条回答
  •  我在风中等你
    2020-11-27 13:01

    If this string is for presentation to the end user, you should use NSNumberFormatter. This will add thousands separators, and will honor the localization settings for the user:

    NSInteger n = 10000;
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    NSString *string = [formatter stringFromNumber:@(n)];
    

    In the US, for example, that would create a string 10,000, but in Germany, that would be 10.000.

提交回复
热议问题