gpt4 book ai didi

ios - 在字符串 iOS 上用逗号分隔数字

转载 作者:可可西里 更新时间:2023-11-01 03:04:52 26 4
gpt4 key购买 nike

当我转换时,我有一个 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 - 在字符串 iOS 上用逗号分隔数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14230413/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com