is there a non jvm way to format a double to strin...
# multiplatform
m
is there a non jvm way to format a double to string with a specific number of decimal places?
j
You could do something like this:
Copy code
import kotlin.math.pow

fun Double.toString(decimalPlaces: Int) = 10.0.pow(decimalPlaces).toInt().let { exp ->
    "${toInt()}.${(this * exp).toInt() % exp}"
}

3.1415926.toString(decimalPlaces = 2)

// Shows 3.14