我想格式化以逗号分隔的数字,与 iphone 计算器格式相同,我只使用以下代码,但它显示错误格式,例如如果我输入 100000 它显示 1,00,000。正确的格式是 100,000 请帮忙
NSNumberFormatter *formatter1 = [[NSNumberFormatter alloc] init];
[formatter1 setNumberStyle:NSNumberFormatterDecimalStyle];
您需要将分组大小添加到 3 :
NSNumberFormatter *formatter1 = [NSNumberFormatter new];
[formatter1 setUsesGroupingSeparator: YES];
[formatter1 setGroupingSeparator: @","];
[formatter1 setGroupingSize: 3];
NSString *numberString = [formatter1 stringFromNumber: [NSNumber numberWithInteger: 1000000]];
关于ios - 用逗号格式化数字与iphone计算器一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22370601/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |