How do you round a number to N decimal places

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
}
8 Likes