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 4 version
Finding locale by currency code:
Formatting currency
Edit:
Why
.lazy
? Without it the loop would run over all the locale identifiers and return the first one which matches. That's about 700ish identifiers, and if the first one is the one you want then you have wasted creating 699 Locales :) With.lazy
in there it automatically stops at the first matching one. In my case it reduces the number of times through the loop from 710 down to 22 when converting "GBP". This isn't important if you are only doing this once, but if you're doing this a number of times (i.e. over an array of symbols) then it's an easy way to get a bit more efficiency.This code is what you are looking for though not very efficient because of loop for locales. Still it works correctly for all currency codes, not just for eur or usd. Hope this will help you.
Use it this way:
Building on code from @Mike Abdullah and @Umka, here are some functions in Swift.