commonMain.io.github.lyxnx.util.Number.kt Maven / Gradle / Ivy
@file:JvmName("Numbers")
package io.github.lyxnx.util
import kotlin.jvm.JvmName
import kotlin.math.round
/**
* Rounds this double to [dp] decimal places
*/
public fun Double.round(dp: Int): Double {
var multiplier = 1.0
repeat(dp) { multiplier *= 10 }
return round(this * multiplier) / multiplier
}
/**
* Rounds this float to [dp] decimal places
*/
public fun Float.round(dp: Int): Float {
var multiplier = 1.0f
repeat(dp) { multiplier *= 10 }
return round(this * multiplier) / multiplier
}