我有以下扩展
extension Double {
func roundToPlaces(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded / divisor
}
}
当我将它更新到 Swift 3 时,它不起作用。我尝试了解决方案 here , 但我得到了
二元运算符“/”不能应用于“_”和“Double”类型的操作数
错误
最佳答案
你忘记了一对括号:应该是 rounded()
而不是 rounded
:
extension Double {
func roundToPlaces(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}
关于swift - 扩展双轮放置 Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41310420/