您好我有将数字转换为本地化价格格式的功能。 但是,当我发送2000我将获得bak 2.000,00 EUR
id喜欢获得2.000欧元(不含美分)
并形成2 000, -
-(NSString *) formatPrice:(NSString *)myPrice
{
NSNumber *price = [NSNumber numberWithInt:[myPrice intValue]];
NSLocale *priceLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"] autorelease]; // get the locale from your SKProduct
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setLocale:priceLocale];
NSString *currencyString = [currencyFormatter internationalCurrencySymbol]; // EUR, GBP, USD...
NSString *format = [currencyFormatter positiveFormat];
format = [format stringByReplacingOccurrencesOfString:@"¤" withString:currencyString];
// ¤ is a placeholder for the currency symbol
[currencyFormatter setPositiveFormat:format];
NSString *myPriceTitle = [currencyFormatter stringFromNumber:price];
return myPriceTitle;
}
THX
答案 0 :(得分:3)
将分隔符设置为@“”(空格),将最大分数设置为零。我认为这应该可以解决问题。
[formatter setCurrencyGroupingSeparator:@" "];
[formatter setMaximumFractionDigits:0];
答案 1 :(得分:0)
稍微好一点的想法可能是设置if([price integerValue] == [price doubleValue])[formatter setMinimumFractionDigits:0];
因为这会根据实际价格正确地计算您的价格,有或没有分数。