swift——数字处理,数字太长用千、万展示
作者:
不洗澡的鱼 | 来源:发表于
2023-07-31 17:58 被阅读0次/**
Int(floor(thousand)):向下取整
round(thousand * 10) / 10:四舍五入保留一位小数
*/
func numberPintUnit(from: Double) -> String{
let number = from
let billion = number / 100_000_000
let kmillion = number / 10_000_000
let million = number / 1_000_000
let wan = number / 10000
let thousand = number / 1000
if billion >= 1.0 {
return "\(Int(floor(billion)))亿+"//\(round(billion * 10) / 10)
}else if kmillion >= 1.0 {
return "\(Int(floor(kmillion)))千万+"
}
else if million >= 1.0 {
return "\(Int(floor(million)))百万+"//\(round(million * 10) / 10)
} else if wan >= 1.0{
return "\(Int(floor(wan)))万+"//\(round(thousand * 10) / 10)
}
else if thousand >= 1.0 {
return "\(Int(floor(thousand)))千+"//\(round(thousand * 10) / 10)
} else {
return "\(Int(number))"
}
}
本文标题:swift——数字处理,数字太长用千、万展示
本文链接:https://www.haomeiwen.com/subject/piwepdtx.html
网友评论