How it's 'false' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How it's 'false'

print(0.1+0.2==0.3)

30th May 2020, 5:02 PM
mandeep nanda
mandeep nanda - avatar
2 Answers
+ 2
Floating point operations Have a look: http://0.30000000000000004.com/
30th May 2020, 5:04 PM
Michi
Michi - avatar
+ 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 ☺️
30th May 2020, 5:12 PM
Hacker Badshah
Hacker Badshah - avatar