Ios 在swift 3中以3位精度舍入双精度值时出错
我用这个扩展来舍入一个精度为3位的双精度值Ios 在swift 3中以3位精度舍入双精度值时出错,ios,double,swift3,Ios,Double,Swift3,我用这个扩展来舍入一个精度为3位的双精度值 extension Double { var DigitsPrecision: String { return String(Double(round(1000*self)/1000)) //round the double with 3 digits precision } } 它在swift 2.2上运行得非常好,但是当我将我的项目迁移到swift 3.0时,它抛出了这个错误 Cannot use mutatin
extension Double {
var DigitsPrecision: String {
return String(Double(round(1000*self)/1000)) //round the double with 3 digits precision
}
}
它在swift 2.2上运行得非常好,但是当我将我的项目迁移到swift 3.0时,它抛出了这个错误
Cannot use mutating member on immutable value: 'self' is immutable
如何解决此问题?我建议您对值本身使用新的
舍入方法:
extension Double {
var digitsPrecision: String {
return String(Double((1000 * self).rounded() / 1000))
}
}
可能重复的