有string
金钱价值
NSString *money = "123456789";
我想印钱,比如 123,456,789
Nik回复了
使用 NSNumberFormatter。
具体来说
NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle]; // this line is important!
NSString *formatted = [formatter stringFromNumber:[NSNumber numberWithInteger:2000000]];
[formatter release];
默认情况下 NSNumberFormatter 使用当前语言环境,因此默认情况下分组分隔符设置为正确的值。关键是要记住设置数字样式。
请参考这些链接
1-链接#one
2-链接#Two
try this:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; //here is money style... or or you can also set your other style
NSString *str = [formatter stringFromNumber:[NSNumber numberWithInt:123456789]];
and also refer following links...
为胜利而战
NSString *decNumberString = [NSNumberFormatter localizedStringFromNumber:[NSNumber numberWithInteger:[str integerValue]]
numberStyle:NSNumberFormatterDecimalStyle];