Kotlin

Kotlin 小數點四捨五入

Kotlin 小數點四捨五入

fun Double.toFixed(s: Int): Double {
    if (s == 0) return round(this)
    val power = (10.0).pow(s)
    return round(this * power) / power
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *