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.
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.
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.
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 (Є).
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.
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.
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