views:

98

answers:

1

Early versions of our app will only support a limited number of currencies. If a user should try to use our app with an unsupported currencyCode then I'd like to set the currencyCode to one that is supported. I'm getting myself confused bouncing between NSNumberFormatters, currencyCodes, NSLocales, etc...

Currently I test the NSNumberFormatter's currencyCode against a list of supported strings: USD, EUR, etc. If lookup is not successful I set the currencyCode to @"USD" then things seem to work but the numbers format in the local style, (50.000,30 US$) vs ($50,000.35), as one would expect. Is this enough? Should I also be setting and tracking the Locale?

Any good tips or tutorials on currencyCodes and/or working with Locales in Cocoa? How are others handling situations like this?

+1  A: 

NSNumberFormatter has both currencySymbol and internationalCurrencySymbol properties. Normally these are defined by the currency code and the locale, but you can set them explicitly if you need. E.g., you can set the internationalCurrencySymbol to "$" if you don't want to see "US$" in non-US locales.

The currency number format is defined by the locale. E.g., the French number format is "50.000 $" vs. "$50,000" in English. If you always want to use English number formatting you can set the number formatter's locale explicitly to "EN".

Darren