3

我编写了下面的代码以使用瑞典货币显示给定价格:

+(NSString *) getPriceStringWithCurrencySymbolFor:(NSNumber *)price{
    NSDictionary *components = [NSDictionary dictionaryWithObject:@"sv_SE" forKey:NSLocaleCurrencyCode];
    NSString *localeIdentifier = [NSLocale localeIdentifierFromComponents:components];
    NSLocale *localeForDefaultCurrency = [[NSLocale alloc] initWithLocaleIdentifier:@"sv_SE"];

    NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
    [currencyFormatter setLocale:localeForDefaultCurrency];
    [currencyFormatter setMaximumFractionDigits:2];
    [currencyFormatter setMinimumFractionDigits:2];
    [currencyFormatter setAlwaysShowsDecimalSeparator:YES];
    [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];

    return [currencyFormatter stringFromNumber:price];
}

它显示价格为 75:00 kr,而应显示为 75,00 kr。我该如何解决?

4

1 回答 1

0

我尝试使用

[currencyFormatter setCurrencyCode:@"SEK"];

但这并没有给出正确的输出。

然后通过这个链接

一种解决方法可能是附加货币字符串,但我不太确定这是否会满足您的要求。

于 2014-02-20T23:50:09.660 回答