去掉自动四舍五入
2021-09-26 本文已影响0人
Smallwolf_JS
extension Float64 {
func decimalString(_ base: Self = 1) -> String {
let tempCount: Self = pow(10, base)
let temp = self*tempCount
let target = Self(Int(temp))
let stepone = target/tempCount
if stepone.truncatingRemainder(dividingBy: 1) == 0 {
return String(format: "%.1f", stepone)
} else {
return "(stepone)"
}
}
}