My iPhone app formats an NSDecimalNumber as a currency using setCurrencyCode, however another screen displays just the currency symbol. Rather than storing both the currency code and symbol, is it possible to derive the symbol from the code? I thought the following might work, but it just returns the symbol as $:
currencyCode = [dictPrices valueForKey:@"currencyCode"];
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setCurrencyCode:currencyCode];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *currencySymbol = [numberFormatter currencySymbol];
You can get number with currency symbol from number with currency code.
This is the way I do:
NSString *currencyCode = @"HKD";
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setCurrencyCode:currencyCode];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
cell.amountLabel.text = [numberFormatter stringFromNumber: expense.exAmount];
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