swift 保留一位和两位小数处理
2021-07-07 本文已影响0人
chushen61
/// 保留一位小数
class func afterDecimals(value: Int) -> String {
let intVal = value / 10000
let doubleVal = value % 10000
let suffixValue = doubleVal / 1000
let newValue = "\(intVal)" + "." + "\(suffixValue)" + "w"
return newValue
}
/// 保留两位小数
class func afterTwoDecimals(value: Int) -> String {
let intVal = value / 10000
let doubleVal = value % 10000
let suffixValue = doubleVal / 100
let newValue = "\(intVal)" + "." + "\(suffixValue)" + "w"
return newValue
}
————————————————
版权声明:本文为CSDN博主「Mackellen」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wangtianya125/article/details/109454189