将float转换为货币String格式器时出现问题

时间:2019-07-14 23:15:16

标签: ios swift numberformatter

转换器Swift 4.2的扩展

extension Float {
    var localeCurrency: String {
        let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        formatter.locale = .current
        return formatter.string(from: self as NSNumber)!
    }
}

访问值

 let   amount = 200.02
    print("Amount Saved Value ",String(format:"%.2f", amountSaving. localeCurrency))

对我来说,它的回报是0.00! 对我来说,扩展性完美访问它时返回0.00!为什么?

0 个答案:

没有答案