2

我正在使用 Cocoa Touch 开发一个 iPhone 应用程序。

我将货币金额与来自 ISO 4217 货币代码列表的相关货币代码一起存储在表格中:

例如:123.45 GBP、456.45 USD、321.98 AUD 等。

当我显示这些值时,我希望它们使用正确的货币符号进行格式化:123.45 英镑、456.45 美元、321.98 美元。

为了在我正在使用的当前语言环境中显示金额

NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];                         
[numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numFormatter setLocale: [NSLocale currentLocale]];

我希望能够从货币代码设置语言环境以显示正确的货币符号。

有没有办法根据货币代码设置语言环境?

4

2 回答 2

0

使用当前语言环境总是更好,因为它是用户可配置的。相反,只需设置货币代码:

[numFormatter setCurrencyCode: theIOSCurrencyCode];
于 2011-02-01T19:22:28.310 回答
0

编辑:修正了一个错字

如果您真的想更改语言环境,您可以在表中存储语言环境标识符而不是货币代码,并按如下方式访问数据:

locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[numFormatter setLocale: locale];
[locale release];
于 2011-02-01T19:35:11.480 回答