2011-09-08 138 views
0

嗨,我有函數將數字轉換爲本地化的價格格式。 但是,當我送2000我會得到李明博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

回答

3

將分隔符設置爲@「」(空格)並將最大分數設置爲零。我認爲這應該可以做到。

[formatter setCurrencyGroupingSeparator:@" "]; 
[formatter setMaximumFractionDigits:0]; 
+0

OOOOO謝謝你古茹:) – vosy

+0

不客氣vosy :)如果你能標記爲答案,將不勝感激。乾杯! – Madhu

0

稍微好一點的想法,可以設置if([price integerValue] == [price doubleValue])[formatter setMinimumFractionDigits:0];因爲這會正確使用或不美分,這取決於實際價格格式化你的價格。