0
Why 6.6/1.1 == 5.99999999999999
I tested in Python and JavaScript: https://code.sololearn.com/Waqx852scgQ6/?ref=app https://code.sololearn.com/c0oRX8qOajM6/?ref=app
2 Answers
+ 6
This happens because accurate division (and operation and representations) with floating is expensive. So it's implemented an approximative algorithm (with less precision) for get more speed.
If you want to be precise. Python 3 you can use decimal library. JS probably have a equivalent library too.
Edit: Here a example:
https://code.sololearn.com/cMkFYAJHmcyY/?ref=app
Edit1: Remember round is not good solution. the imprecision can make round miss sometimes.
+ 4
Floating point arithmatic is not 100% accurate all the time due to multiple reasons stated here:
https://stackoverflow.com/questions/2100490/floating-point-inaccuracy-examples