Ios 如何以1.750科威特第纳尔的格式显示价格
我有以下代码来显示价格字符串:Ios 如何以1.750科威特第纳尔的格式显示价格,ios,currency,Ios,Currency,我有以下代码来显示价格字符串: +(NSString *) getPriceStringWithCurrencySymbolFor:(NSNumber *)price{ AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; if([appDelegate.shop.localeCode isEqualToString:@"ar_AE"]) return [NSStri
+(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];
}
到目前为止,它运作良好。但现在,我应该显示科威特迪纳里的货币。如果我将appDelegate.shop.localeCode设置为ar_KW,则函数将给出阿拉伯语的价格。我需要的是,显示像1.750 KWD的价格。我该怎么做呢?你好,Burak,我建议你看看下面的sof回答谢谢你@casillas。当我编写代码时,这个主题对我帮助很大。但我现在有一个不同的问题。我的客户不希望价格以阿拉伯字母显示。