2014-02-20 49 views
3

我寫了下面的代碼,以顯示給定的價格與瑞典貨幣:如何在IOS顯示正確的瑞典貨幣?

+(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。我該如何解決這個問題?

+0

什麼樣的價值,你傳遞了'appDelegate.shop.localeCode'? – footyapps27

+0

我編輯過。請檢查。 – Burak

+0

我可以複製它,我覺得這是基金會的錯誤。 –

回答

0

我嘗試使用

[currencyFormatter setCurrencyCode:@"SEK"]; 

,但沒有給出正確的輸出。

然後通過this link

去一個解決可能追加貨幣的字符串,雖然我不太清楚這是否會滿足您的要求。