从float转换为nsdecimalnumber总是失败迅速

时间:2017-02-28 14:31:13

标签: swift3

我正在通过Web服务读取我的数据,该服务返回一个字符串的百分比,我需要在我的应用程序中正确格式化它。目前,我收到一条错误消息,内容为"参数标签'(_:)'不匹配任何可用的重载"。

有关如何解决此问题的建议?

            if let dUnInsured = result[0]["UnInsured"] as? String, let doubleNum = Double(dUnInsured) {
                let sUnInsured = dollarFormatter.string(from: (NSDecimalNumber(Decimal(doubleNum))))!
                self.inUninsured.text = sUnInsured
            }

1 个答案:

答案 0 :(得分:0)

尝试这样。

if let dUnInsured = result[0]["UnInsured"] as? String, let doubleNum = Double(dUnInsured) {
    let sUnInsured = dollarFormatter.string(from: (NSNumber(value: doubleNum)))!
    self.inUninsured.text = sUnInsured
}