icest0
February 5, 2021, 2:13pm
1
I’m currently doing the last project of javascript algorithm.
Here is my code
console.log(60 + 20 + 15 + 1 + 0.50 + 0.20 + 0.04)
the output is 96.74000000000001
the problem seems to be the last number “0.04” if I change it to “0.03” or “0.05” it works fine.
You have discovered one of the problems with floating point values. Computers can’t exactly store decimal numbers, so the arithmetic will have rounding errors.
I recommend using a whole number of cents instead. No decimals means no rounding.
1 Like
ilenia
February 5, 2021, 2:15pm
3
a computer can’t store precisely decimal numbers
You can get some more explanation in this video:
2 Likes
icest0
February 5, 2021, 2:16pm
4
that was very quick, I have also seen ieahleen’s reply. I will check the video out, thanks you so much.
1 Like
system
Closed
August 7, 2021, 2:16am
5
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.