+ 5

This code sometimes doesn't work and it prints out something like 0.1999999999996$ instead of 0.20$ Please help!

https://code.sololearn.com/cmmDArPVDd7D/?ref=app

19th Dec 2018, 12:50 PM
Catzzzz™
Catzzzz™ - avatar
6 Respuestas
+ 10
https://javarevisited.blogspot.com/2012/02/java-mistake-1-using-float-and-double.html?m=1 Ok, here is the explaination.
19th Dec 2018, 1:15 PM
GiveAway
GiveAway - avatar
+ 9
Lol yes that bcs of Amazing floats. Use round instead.
19th Dec 2018, 1:02 PM
GiveAway
GiveAway - avatar
+ 7
Or why dont you make it an integer, and divide it when outputing it?
19th Dec 2018, 1:03 PM
GiveAway
GiveAway - avatar
+ 3
What do you mean I should use Rounds? I'm sorry if I'm dumb but Im not sure what round is.
19th Dec 2018, 1:07 PM
Catzzzz™
Catzzzz™ - avatar
+ 3
Thanks for the help, I will change it soon! :D
19th Dec 2018, 1:17 PM
Catzzzz™
Catzzzz™ - avatar
+ 3
It's done now!
19th Dec 2018, 3:02 PM
Catzzzz™
Catzzzz™ - avatar