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

commonMain.io.github.lyxnx.util.Number.kt Maven / Gradle / Ivy

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy