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