0

我有一个问题,如果您将我的应用程序上的货币更改为与区域设置不同的货币,我的应用程序会错误地显示负值,例如应用程序货币设置为 £,区域设置为美国,我的负数显示为 ( 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];
4

0 回答 0