Cocoa Touch display Multiple Currencies

364 views Asked by At

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 : £ 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 ?

2

There are 2 answers

1
David On

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];
2
Costique On

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

[numFormatter setCurrencyCode: theIOSCurrencyCode];