How do you round a number to N decimal places


So I saw this post about my problem(Print floats with certain amount of decimal numbers)

And I was wondering I it possible to use a methood or something else rather “%.2f”.format(value) in order to achive the same thing


You should explain better you problem.

Technically you cannot round the IEEE 754 floating point 0.1 to the first decimal point.

However you can use

fun Double.round(decimals: Int): Double {
    var multiplier = 1.0
    repeat(decimals) { multiplier *= 10 }
    return round(this * multiplier) / multiplier


I’m just trying to short the number to lets say 2 decimal places.

for example I want to turn:
to just

I hope you can understand me know, or at least more clear to understand.