0
Need help
0.2 + 0.2 + 0.2 == 0.6 returns False and 0.2 + 0.2 == 0.4 returns True. What's the reason for this?
3 Antworten
+ 4
It is inherent to how computers represent data. IT DOES NOT MEAN THAT THE COMPUTER WRONG.
+ 3
You should take a look at this:
https://www.sololearn.com/post/1713746/?ref=app
Floating point numbers can never be precise, they are only approximations constrained by the number of bits used to store the value.
So comparing for equality should be done with regard to an acceptable error threshold.
0
Are you using Python?
Try below code and see the result.
x = 0.2 + 0.2 + 0.2
print(x)
Don't ask me detail, I don't know much.
As far as i know computer use of binary system (0 and 1) is the root reason, which have an impact on how accuracy a computer can handle floating point number.