Supporting limited number of currencies in Cocoa(Touch)
Early versions of our app will only support a limite开发者_运维百科d 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?
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".
精彩评论