I have a Double variable that is 0.0449999
and I would like to round it to 1 decimal place 0.1
.
I am using Kotlin but the Java solution is also helpful.
val number:Double = 0.0449999
I tried getting 1 decimal place with these two solutions:
val solution = Math.round(number * 10.0) / 10.0
val solution = String.format("%.1f", number)
The problem is that I get 0.0 in both cases because it rounds the number from 0.04
to 0.0
. It doesn't take all decimals and round it.
I would like to obtain 0.1: 0.045 -> 0.05 -> 0.1