Simon Schubert
10/21/2019, 4:30 PM33
or 66
. So I wrote a function like value - value.toInt()
which returns e.g. 0.33f
. I thought it works fine. But today I noticed that for some values it doesn’t work. For example: 8.33 returns 0.32999992
. I assume it's already a known bug? Anyway I found that very odd. Whats an efficient workaround?
for(i in 0..8) {
println("${8.33f - i}")
}
returns
8.33
7.33
6.33
5.33
4.33
3.33
2.33
1.3299999
0.32999992
1.3.50 jvmelizarov
10/21/2019, 4:43 PMSimon Schubert
10/21/2019, 6:05 PM"%.2f".format(value - value.toInt())
elizarov
10/22/2019, 7:37 AMround((value - value.toInt()) * 100) / 100
.Simon Schubert
10/22/2019, 9:53 AMf
at the very end. Thanks a lot! round((value - value.toInt())*100)/100f