Is it possible to derive currency symbol from currency code?

前端 未结 5 1604
鱼传尺愫
鱼传尺愫 2021-02-04 19:04

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 cod

5条回答
  •  粉色の甜心
    2021-02-04 19:27

    You want to be setting the locale, not the currency code. Then you will get the expected results from the formatters properties (or tweak them). You can also get things like the currency symbol from the locale object itself. So, for example, if you were displaying a number formatted for Japan in JPY:

    NSLocale* japanese_japan = [[[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"] autorelease];
    NSNumberFormatter *fmtr = [[[NSNumberFormatter alloc] init] autorelease];
    [fmtr setNumberStyle:NSNumberFormatterCurrencyStyle];
    [fmtr setLocale:japanese_japan];
    

    Now your number formatter should give you the correct symbols for currency symbol and format according to the rules in the specified locale.

提交回复
热议问题