1 数量格式化处理:
private var format = NumberFormat.getNumberInstance()
/**
* 格式化数量显示
*/
fun formatCount(count: Int?): String? {
return if (count == null) {
"0"
} else {
format.maximumFractionDigits = 2//设置保留小数位数
format.roundingMode = RoundingMode.FLOOR//设置舍入方式
when {
count!! < 1000 -> "$count"
count in 1000..9999 -> "${format.format(count.toFloat() / 1000)}k"
else -> "${format.format(count.toFloat()!! / 10000)}w"
}
}
}
网友评论