0
Kotlin Double
Well, if you know, the shipping task after quiz #3 is kinda weird for me, just because: Expected output: 29.945 (forgot the number, but it won't affect me to explain) My output: 29.945000000003 How to round the number to 3 decimals after a dot? Is there in Kotlin some functions for this?
5 ответов
+ 7
It's a popular issue in the most of the programming languages. This topic is different but same concept. Take a look at this thread
https://www.sololearn.com/Discuss/1288636/?ref=app
+ 6
var num: Double = String.format("%.3f", 29.9450000003).toDouble()
println(num)
But, I think we don't need to use this for that task. Can we see your code?
+ 5
Instead of a/100*15 try a*15/100 to avoid these kind of floating points errors.
+ 1
0
Simba why do they appear?