Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to derive currency symbol from currency code?

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];
like image 741
Dave Hunt Avatar asked Apr 04 '10 10:04

Dave Hunt


Video Answer


1 Answers

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];
like image 186
zgjie Avatar answered Nov 15 '22 00:11

zgjie