How do you round a number to N decimal places

fun Double.round(decimals: Int = 2): Double = "%.${decimals}f".format(this).toDouble()

3 Likes