1
我试图格式化一个数字作为货币。快速格式化货币返回无
let formatter = NSNumberFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_GB")
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
let limit = formatter.numberFromString("12.99") as? NSDecimalNumber
但是,常数限制返回为零。奇怪的是,这段代码直到最近才开始工作,但不知道可能发生了什么变化。这个例子看起来好吗,还是我错过了什么?
EDIT
为了给出上下文中,我试图解析字符串编号(从输入元件)为十进制数,用于存储作为货币值。我的错误出现在设置数字样式,我正在使用.CurrencyStyle
,但应使用.DecimalStyle
。
感谢您的回答。格式化程序使用了错误的numberStyle。 – Kevin 2015-04-04 18:11:55