commonMain.korlibs.math.RoundDecimalPlaces.kt Maven / Gradle / Ivy
package korlibs.math
import kotlin.math.*
fun Float.roundDecimalPlaces(places: Int): Float {
if (places < 0) return this
val placesFactor: Float = 10f.pow(places.toFloat())
return round(this * placesFactor) / placesFactor
}
fun Double.roundDecimalPlaces(places: Int): Double {
if (places < 0) return this
val placesFactor: Double = 10.0.pow(places.toDouble())
return round(this * placesFactor) / placesFactor
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy