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.
public final Map<String, String> CURRENCIES= new HashMap<String, String>(){ { put("EUR","€"); put("USD","$"); ... } }; Then, you can get the symbol by using Locale, like this. Show activity on this post. You can simply use this code to get the currency symbol and different currency formats.
The getSymbol() method is used to get the symbol of a given currency for the default DISPLAY locale. For example, for the US Dollar, the symbol is "$" if the default locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.
You get all the currency symbols except the Baht for free on the US keyboard. Press and hold the $ symbol and you'll see all the alternates. To get the Baht symbol - add the thai keyboard and the Baht symbol will be added to the US keyboard. You don't need to switch to that keyboard - just add it.
This code works charm in my project. I will share this to you all.
NSString *currencyCode = @"EUR"; NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:currencyCode] autorelease]; NSString *currencySymbol = [NSString stringWithFormat:@"%@",[locale displayNameForKey:NSLocaleCurrencySymbol value:currencyCode]]; NSLog(@"Currency Symbol : %@", currencySymbol);
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With