Kotlin Program to Round a Number to n Decimal Places. In the below program, we’ve used format() method to print the given floating-point number num to 4 decimal places.
Kotlin Program to Round a Number to n Decimal Places
Source Code
import java.math.RoundingMode
import java.text.DecimalFormat
fun main(args: Array<String>) {
val num = 1.23467
val df = DecimalFormat("#.###")
df.roundingMode = RoundingMode.CEILING
println(df.format(num))
}
Output
Kotlin Program to Round a Number to n Decimal Places