我有一个数字格式化程序:
let currencyFormatter:NSNumberFormatter = NSNumberFormatter()
currencyFormatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
currencyFormatter.currencyCode = "$"
将其设置为标签:
cell.ValueLabel.text = currencyFormatter.stringFromNumber(product.price)
获取100.00
而不是100.00$
答案 0 :(得分:2)
您必须设置currencySymbol而不是currencyCode
let currencyFormatter = NSNumberFormatter()
currencyFormatter.numberStyle = .CurrencyStyle
currencyFormatter.currencySymbol = "$"
currencyFormatter.stringFromNumber(100) // $100.00"
否则
let currencyFormatter = NSNumberFormatter()
currencyFormatter.numberStyle = .CurrencyStyle
currencyFormatter.currencyCode = "USD"
currencyFormatter.stringFromNumber(100) // $100.00"