代码如下,输入要保留的小数个数
extension Double {
/// Rounds the double to decimal places value
func roundTo(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}
时间: 2024-10-14 04:50:09
代码如下,输入要保留的小数个数
extension Double {
/// Rounds the double to decimal places value
func roundTo(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}