用字符串iOS上的逗号分隔数字

当我转换时,我有一个NSInteger(比如值60000)
然而,它要串起来,我希望得到“60,000”
“60000”有办法吗?谢谢.

解决方法

使用数字格式化程序:
NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
[fmt setNumberStyle:NSNumberFormatterDecimalStyle]; // to get commas (or locale equivalent)
[fmt setMaximumFractionDigits:0]; // to avoid any decimal

NSInteger value = 60000;

NSString *result = [fmt stringFromNumber:@(value)];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...