我有一個數字格式化程序設置爲貨幣字符串轉換爲十進制值。問題是,如果文本字符串沒有前導美元符號(「$」),它將被轉換爲0,而不是有效的匹配數字。所以:
"$3.50" converts to 3.50
"3.50" converts to 0
這裏是轉換器的代碼:
// formatter to convert a value to and from a currency string
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setGeneratesDecimalNumbers:YES];
我缺少的東西?