Kulwinder Dhanjal
09/10/2021, 8:18 AMfun Float.round(decimals: Int = 2): Float = "%.${decimals}f".format(this).toFloat()
ephemient
09/10/2021, 8:45 AMimport kotlin.math.pow
import kotlin.math.round
fun Double.roundDecimal(digits: Int = 2): Double {
val scale = 10.0.pow(digits)
return round(this * scale) / scale
}
fun Float.roundDecimal(digits: Int = 2): Float {
val scale = 10.0f.pow(digits)
return round(this * scale) / scale
}
Kulwinder Dhanjal
09/10/2021, 9:29 AM