How it's 'false' | SoloLearn: Learn to code for FREE!

+1

How it's 'false'

print(0.1+0.2==0.3)

5/30/2020 5:02:46 PM

mandeep nanda

2 Answers

New Answer

+2

Floating point operations Have a look: http://0.30000000000000004.com/

+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 ☺️