+ 1
Can anyone tell me why 0.1+0.2==0.3 gives false answer?
3 ответов
+ 1
Well it's much interesting.
Listen, We can only express fractions that denominater have prime factors of the base. Otherwise we get repeating decimals.
Like in base 10, 1/8 1/4 can be expressed cleanly whereas 1/7 1/3 can't
Same in base 2, 1/10(0.1) and 1/5(0.2) are repeating decimals
When we add them they get leftover which get carried up when converted to base 10(decimal).
Thus, 0.1+0.2 != 0.3
They actually Equals 0.30000000000000004
Thank You ☺️
0
The problem is that floating point numbers don't have unlimited precision. Therefore, instead of checking for equality, you should check, if they are almost equal.
For more information: http://0.30000000000000004.com/
0
Because computers can't count