Why doesn't 0.1+0.2-0.3 equal 0.0 ? according to normal equation the result should be 0 but why isn't it?
Could someone please explain me the reason?
Why doesn't 0.1+0.2-0.3 equal 0.0 ? according to normal equation the result should be 0 but why isn't it?
Could someone please explain me the reason?
All programming languages including Python use 32-bit floating point representation for numbers. With decimal fractions, this floating-point number system causes some rounding errors which results in 0.1 + 0.2 == 0.3
as false
.
For Example:
1.2
is exactly equal to 1.1999999999999999555910790149937383830547332763671875
Solution:
One solution to handle this inconsistency in floating-point value is by using a native Python module called Decimal
For Detailed Answer, Read these articles: