我遇到问题,如果您将我的应用中的货币更改为与区域设置不同的内容,我的应用会错误地显示负值,例如应用货币设置为£,locale设置为美国,我的负数显示为($ 278.00)。我希望它显示 - £278.00。我使用以下格式编号:
// Get the currency from the user settings/preferences
NSString *currency = [[NSUserDefaults standardUserDefaults] objectForKey:CURRENCY_KEY];
// Set the format, currency and negative format so that we don't display the default (xx.xx)
NSNumberFormatter *numberCurrencyFormatter = [[NSNumberFormatter alloc] init];
[numberCurrencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberCurrencyFormatter setCurrencySymbol:currency];
[numberCurrencyFormatter setCurrencyDecimalSeparator:[[NSLocale currentLocale] objectForKey:NSLocaleDecimalSeparator]];
if ([[[NSLocale currentLocale] objectForKey:NSLocaleDecimalSeparator] isEqualToString:DECIMAL]) {
[numberCurrencyFormatter setCurrencyGroupingSeparator:COMMA];
[numberCurrencyFormatter setNegativeFormat:[currency stringByAppendingString:@"-#,##0.00"]];
} else {
[numberCurrencyFormatter setCurrencyGroupingSeparator:DECIMAL];
[numberCurrencyFormatter setNegativeFormat:[currency stringByAppendingString:@"-#.##0,00"]];
}
return [numberCurrencyFormatter stringFromNumber:number];