【发布时间】:2021-12-27 16:27:58
【问题描述】:
我有一个简单的问题,但我没有找到解决方案。我有很大的负数 ex(-6763.98) 我想要的是这样的 ex($-6.78K)。 A 发现了许多适用于正数的解决方案,但没有一个适用于负数的解决方案。这是我现在拥有的代码。
const val COUNT_DIVISOR = 1000
const val COUNT_DIVISOR_FLOAT = 1000.0
fun getFormattedNumber(count: Long): String {
if (count < COUNT_DIVISOR) return "" + count
val exp = (ln(count.toDouble()) / ln(COUNT_DIVISOR_FLOAT)).toInt()
return resources.getString(
R.string.decimal_format_long_number_price,
count / COUNT_DIVISOR_FLOAT.pow(exp.toDouble()), EXTENSION[exp - 1]
)
}
【问题讨论】:
-
这会有帮助吗? “如果(计数 -1000.0)”
标签: android kotlin string-formatting