Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: How to get local currency symbol (i.e. "$" instead of "AU$")

Here's a code of how I get currency symbol now:

NSLocale *lcl = [[[NSLocale alloc] initWithLocaleIdentifier:@"au_AU"] autorelease]; NSNumberFormatter *fmtr = [[[NSNumberFormatter alloc] init] autorelease]; [fmtr setNumberStyle:NSNumberFormatterCurrencyStyle]; [fmtr setLocale:lcl];  NSLog( @"%@", [lcl displayNameForKey:NSLocaleCurrencySymbol value:@"AUD"] ); NSLog( @"%@", [fmtr currencySymbol] ); 

Both NSLogs return "AU$". As I understood from Apple development documentation, there are at least two currency symbols for each currency (these symbols could be the same, though) - local (that is used within a country. $ for Australia, for example) and international (AU$ for Australia). So, the question is how to get LOCAL currency symbol. Any ideas?

Thanks in advance.

like image 325
kovpas Avatar asked Dec 13 '10 10:12

kovpas


People also ask

How do I get the euro symbol on my Iphone?

The € symbol is Option-Shift-2 (Option-2 gives you the ™ symbol). Go to system preferences > keyboard > input sources and make sure there is only one item on the list, and that the name of that item is "British". Then you will find € at option 2 as printed on your British keyboard.

How do I get the currency symbol from locale?

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.

What is the e looking symbol in currency?

Currency Symbols FAQs The symbol € is called the Euro symbol. The ISO code for the euro is EUR. It is used by 19 member countries of the European Union and the design is based on the Greek letter epsilon (Є).


2 Answers

NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [currencyFormatter setLocale:[NSLocale currentLocale]]; [currencyFormatter setMaximumFractionDigits:2]; [currencyFormatter setMinimumFractionDigits:2]; [currencyFormatter setAlwaysShowsDecimalSeparator:YES]; [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];  NSNumber *someAmount = [NSNumber numberWithFloat:5.00];     NSString *string = [currencyFormatter stringFromNumber:someAmount]; 

You will receive $5.00 for US, ¥5.00 for Japan, 5.00€ for Europe, etc.

like image 67
Valentyn Kuznietsov Avatar answered Sep 24 '22 06:09

Valentyn Kuznietsov


This snippet returns the currency symbol ¥ for locale "ja_JP" (could be any other locale).

NSLocale* japanese_japan = [[[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"] autorelease];  NSNumberFormatter* fmtr = [[[NSNumberFormatter alloc] init] autorelease];  [fmtr setNumberStyle:NSNumberFormatterCurrencyStyle];  [fmtr setLocale:japanese_japan];   // Local currency symbol (what you're asking for)  NSString* currencySymbol = [fmtr currencySymbol];  NSLog( @"%@", currencySymbol ); // Prints '¥'   // International currency symbol   NSString* internationalCurrencySymbol = [fmtr internationalCurrencySymbol];  NSLog( @"%@", internationalCurrencySymbol ); // Prints 'JPY' 

It's unfortunate that for au_AU you get AU$ as the local currency symbol instead of just $, but that must be the way it's meant to be displayed on iOS. However note that the international symbol printed for au_AU is not AU$ but AUD.

like image 22
Julio Gorgé Avatar answered Sep 24 '22 06:09

Julio Gorgé