All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.korlibs.math.RoundDecimalPlaces.kt Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
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