0.1+0.2
Is 0.1 + 0.2 0.3The reason why 0.1 + 0.2 != 0.3 in Python (and in many other programming languages) is because of how floating-point numbers are represented in computers.
Floating-point numbers are represented in binary, which means that numbers that have a finite decimal representation in base 10 (such as 0.1 and 0.2) may not have a finite binary representation. Therefore, when we try to represent these numbers in binary, there may be some loss of precision.
In particular, the decimal values 0.1 and 0.2 cannot be represented exactly in binary, and therefore they are approximated by the closest binary numbers that can be represented. When these approximations are added together, the result is not exactly equal to the binary representation of the decimal value 0.3.
Therefore, when we write 0.1 + 0.2 == 0.3 in Python, the result is False because the sum of 0.1 and 0.2 is not exactly equal to 0.3 due to the limitations of floating-point arithmetic.
To perform exact decimal arithmetic in Python, you can use the decimal module, which provides support for arbitrary-precision decimal arithmetic
More blog posts by heckerboy
![](https://image.lichess1.org/display?h=250&op=thumbnail&path=heckerboy:ublog:ZkeOa9yG:3ECx2aYv.png&w=400&sig=9c5a25f1074c7047575e101123220e3b8398413d)
Guess the ELO ep1
I know it is like Levy's videos, but hey we are doing our best okay ? anyways in this series we will…![](https://image.lichess1.org/display?h=250&op=thumbnail&path=heckerboy:ublog:gkKPdBmI:6oIvD4Eo.png&w=400&sig=f8072e1a51e600cde440a850c085b1b7a476b877)
How to not hung peices in chess
Have you ever hung your queen in a middle of a game evn if you were totally focused, this blog will …![](https://image.lichess1.org/display?h=250&op=thumbnail&path=heckerboy:ublog:67bxyVbm:SpMgbAmO.png&w=400&sig=cd574865b8aa35d87878ffe5c876656c1f65bbf3)
This Man Saved your Life and Mine
If it was not for him, we would probably be both dead, but who is he?![](https://image.lichess1.org/display?h=250&op=thumbnail&path=heckerboy:ublog:F4FzmPGy:kfHPgXuq.png&w=400&sig=95e5c89adc060ba473f9e892cbb69d7d36af0ec7)