似乎在iOS 13中,它改变了NSNumberFormatter显示数字的方式。以前在iOS 12中,将区域格式设置为哥伦比亚,对于一个12.00的数字,它将显示为12,这是正确的。然而现在在iOS 13中,它显示为12,00,这是不正确的,因为在哥伦比亚,它不应该在12的后面显示,00。任何想法在iOS 13中发生了什么变化,我们如何能解决这个问题?
这是我的代码。谢谢
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setCurrencySymbol:@""];
NSString *floatString = [NSString stringWithFormat:@"%.2f", floatValue];
NSDecimalNumber* number = [NSDecimalNumber decimalNumberWithString:floatString];
NSString *numberString = [formatter stringFromNumber:number];
NSLog(@"%@", numberString");
更新:更新到iOS 13.2后,这个问题消失了。
在iOS 13.1中有一个bug,当你的小数点与其他任何事物的小数点不同,而不是.。
例如,: 我的地区是波兰。所以,如果我有金额字符串="4.5". 下面的代码总是返回nil。
let currencyFormatter = NumberFormatter()
currencyFormatter.currencySymbol = ""
currencyFormatter.numberStyle = .currency
currencyFormatter.locale = Locale.current
if let finalNumber = currencyFormatter.number(from: amountString){
return finalNumber.doubleValue
}
return nil