如何以科威特第纳尔的1.750 KWD格式显示价格

时间:2015-03-23 15:50:05

标签: ios currency

我有以下代码来显示价格字符串:

+(NSString *) getPriceStringWithCurrencySymbolFor:(NSNumber *)price{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if([appDelegate.shop.localeCode isEqualToString:@"ar_AE"])
    return [NSString stringWithFormat:@"%d",[price integerValue]];
NSDictionary *components = [NSDictionary dictionaryWithObject:appDelegate.shop.localeCode forKey:NSLocaleCurrencyCode];
 NSString *localeIdentifier = [NSLocale localeIdentifierFromComponents:components];
 NSLog(@"localeIdentifier: %@", localeIdentifier);
 NSLocale *localeForDefaultCurrency = [[NSLocale alloc] initWithLocaleIdentifier:appDelegate.shop.localeCode];

 NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
 [currencyFormatter setLocale:localeForDefaultCurrency];
 [currencyFormatter setMaximumFractionDigits:3];
 [currencyFormatter setMinimumFractionDigits:0];
 [currencyFormatter setAlwaysShowsDecimalSeparator:YES];
 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
if([appDelegate.shop.localeCode isEqualToString:@"ar_KW"]){
    [currencyFormatter setCurrencyDecimalSeparator:@"."];
}
else{
    [currencyFormatter setCurrencyDecimalSeparator:@","];
}
 NSLog(@"currency symbol: %@", [currencyFormatter currencySymbol]);
 return [currencyFormatter stringFromNumber:price];

}

直到现在,它运作良好。但现在,我应该为科威特Dinari展示货币。如果我为ar_KW(科威特)设置appDelegate.shop.localeCode,该函数以阿拉伯语给出价格。我需要的是,显示价格如“1.750 KWD”。我怎么能这样做?

0 个答案:

没有答案