开发者

Cocoa Touch display Multiple Currencies

I am using Cocoa Touch to develop an iPhone App.

I am storing currency amounts in a table along with associated Currency Codes From the ISO 4217 Currency Code List :

for example : 123.45 GBP, 456.45 USD, 321.98 AUD etc.

When I am displaying these values I want them to be formatted using the correct Currency Symbol 开发者_Python百科: £ 123.45, $ 456.45, $ 321.98.

For displaying amounts in the current locale I am using

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

I want to be able to set up a locale from the Currency Codes to display the correct Currency Symbol.

Is there any way to set up a locale given the Currency Code ?


It is always better to use the current locale since it's user-configurable. Instead, just set the currency code:

[numFormatter setCurrencyCode: theIOSCurrencyCode];


Edit: fixed a typo

If you really want to change the locale you could store the locale identifiers instead of currency codes in your table and access the data as follows:

locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[numFormatter setLocale: locale];
[locale release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜