似乎NSNumberFormatter無法將歐元(也可能是其他)貨幣字符串解析爲數字類型。有人可以證明我錯了。使用NSNumberFormatter從國際貨幣字符串中獲取十進制值
我試圖使用以下方法來從貨幣字符串得到一個數字量:
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *currencyNumber = [currencyFormatter numberFromString:currencyString];
這工作得很好英國和美國的貨幣金額。它甚至可以處理$和£以及數千個分隔符,而且沒有問題。
但是,當我使用歐元貨幣數量(在設置應用程序中將區域格式設置爲法國或德國)時,它將返回一個空字符串。以下所有字符串失敗:
12,34 €
12,34
12.345,67 €
12.345,67
值得一提的是,這些字符串使用相應的語言環境時,正是出來的NSNumberFormatter的stringFromNumber方法的匹配。
地區格式設置到法國在設置應用程序,然後在下面的代碼中設置currencyNumber至12.34,在的currencyString結果被設置爲'12,34€」:
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *currencyString = [currencyFormatter stringFromNumber:currencyNumber];
這顯然是相當這個問題很容易針對歐元進行解決,但我希望能夠在儘可能多的國家銷售這個應用程序,而且我認爲類似的情況一定會發生在其他地區。
有沒有人有答案?
TIA,鄧肯
我還沒有找到解決方案,所以任何輸入都將不勝感激。謝謝,鄧肯 – pieSquared 2010-09-15 10:25:22
我會建議提交一份錯誤報告。 – 2011-05-06 07:19:54