2011-08-14 109 views
1

我正在應用程序中執行應用程序內購買。 爲了得到本地化的價格,我做到以下幾點:在格式化價格時獲取NSNumberFormatter來拼出貨幣

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; 
    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; 
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; 
    [numberFormatter setLocale:self.priceLocale]; 
    NSString *formattedString = [numberFormatter stringFromNumber:self.price]; 
    [numberFormatter release]; 
    return formattedString; 

這工作得很好。不過,我想獲得一個可轉換爲ASCII字符串的字符串。那麼有沒有辦法讓數字格式化程序拼出貨幣。例如「0.99歐元」將變爲「0.99歐元」或「0.99歐元」。

回答

0

有一個辦法做到這一點通過格式化的格式替換¤

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; 
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; 
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; 
[numberFormatter setLocale:self.priceLocale]; 
NSString *currencyString = [numberFormatter internationalCurrencySymbol]; 
NSString *posFormat = [numberFormatter positiveFormat]; 
formatterFormat = [formatterFormat stringByReplacingOccurrencesOfString:@"¤" withString:currencyString]; 
[numberFormatter setPositiveFormat:posFormat]; 
NSString *formattedString = [numberFormatter stringFromNumber:self.price]; 
[numberFormatter release]; 
return formattedString;