I have get currency code (Eg: USD, EUR, INR) from webservice response. I need to show the currency symbols for the corresponding currency code. If the currency code is USD, i need to show $, if the currency code is EUR i need to show €. How can i do this? Please suggest any idea or sample code to do this. Please help me. Thanks in advance.
相关问题
- NSOutlineView drag line stuck + blue border
- How to refresh the NSLocale in iPhone?
- iphone sdk see size of local file (one created
- How can you detect the connection and disconnectio
- Java Money - currency conversion rate on specific
相关文章
- Converting (u)int64_t to NSNumbers
- “getter” keyword in @property declaration in Objec
- NSMenuItem KeyEquivalent “ ”(space) bug
- Is working with money (decimal numbers) in PHP con
- Detect if cursor is hidden on Mac OS X
- NSNumberFormatter doesn't allow typing decimal
- Is subclassing NSNotification the right route if I
- Creating an NSMutableArray with a literal via muta
Swift
This code works charm in my project. I will share this to you all.
Thanks.
One way is to start with a valid locale (e.g. the user current locale) and then override the currency code. Simple and efficient and allows you to use the newly constructed locale to configure a currency formatter in order to display a string according to the user's locale preferences:
NSLocale
will happily tell you the currency symbol used by a particular locale:It'll also tell you the currency code:
So all you have to do now is look up the locale that corresponds to a given code. There's no built-in method (that I'm aware of) to do this directly, so loop through all the known locales and pick the one that matches. @Umka's answer has a good example of this in the
-findLocaleByCurrencyCode:
method.You could optimise the process by building your own lookup table, rather than iterating through all locales each time. You may need to handle the possibility of duplicate currency codes too, which would require some heuristic for deciding which is the most likely locale.
this is for US currency style
This is for indian