kotlin number to k m b

fun formatNumber(num: Long): String {
    if (num < 1e3) return "$num"
    val exp = (Math.log(num.toDouble()) / Math.log(1e3)).toInt()
    return String.format("%.1f %c", num / Math.pow(1e3, exp.toDouble()), "kMB"[exp - 1])
}