我有这些数字格式:
100000,459
100000459
100.000
100.000,59
100.000.000,39
数字会随着用户向其输入值而变化。对于每个添加的值,我需要使用 NSNumberFormatter 重新格式化数字。问题是这个数字已经有了。和 ,并且格式化程序似乎无法正确处理这些。结果是这样的:
100 000,00
100 000 459,00
100,00
100,00
100,00
例如,我希望 100000,459 变为 100 000,459。
我现在使用的代码:
NSNumber *amount = [NSNumber numberWithInt:[string intValue]];
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"nb_NO"];
[currencyFormatter setLocale:locale];
NSString *commaString = [currencyFormatter stringForObjectValue:amount];
如何格式化已经格式化的数字?