美文网首页
去掉自动四舍五入

去掉自动四舍五入

作者: Smallwolf_JS | 来源:发表于2021-09-26 19:19 被阅读0次

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)"
}
}
}

相关文章

网友评论

      本文标题:去掉自动四舍五入

      本文链接:https://www.haomeiwen.com/subject/hpqcnltx.html