Is it possible to derive currency symbol from currency code?

前端 未结 5 1666
鱼传尺愫
鱼传尺愫 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:22

    The following code will return only the currencySymbol for a given currencyCode

    - (NSString*)getCurrencySymbolFromCurrencyCode:(NSString*)currencyCode {
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        [formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
        [formatter setCurrencyCode:currencyCode];
        [formatter setMaximumFractionDigits:0];
        NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:0]];
        [formatter release];
        return [string substringFromIndex:1];
    }
    

提交回复
热议问题