1
我試圖將一些貨幣字符串(例如$ 25 000)到NSDecimalNumber用下面的代碼:轉換貨幣字符串到NSDecimalNumber
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[currencyFormatter setGeneratesDecimalNumbers:TRUE];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
// textField.text is some currency string (e.g., $25,000)
NSDecimalNumber *decimalNumber = [currencyFormatter numberFromString:textField.text];
編譯器抱怨產生的CurrencyFormatter的類型,是NSNumber的替代的NSDecimalNumber,但我在這裏設置:
[currencyFormatter setGeneratesDecimalNumber:TRUE];
所以我迷路了。有任何想法嗎?
謝謝dasblinkenlight,不可能更明顯。 –