Can anyone please help me explain this fact? I tried to read some articles on the web about floating point but it is always a hard topic for me to understand.
This is what I get from Python 3.3.0
A brief to medium explanation is enough. It is really appreciated. Thanks!

The simple answer is because the computer stores numbers in binary: $0.3$ should have been stored as $$0.01001100110011001100\ldots$$However, a computer does not have infinite storage space, so it has to round it to some specified number of bits. Therefore it is not exactly $0.3$ that gets stored, but something roughly $10^{-16}$ smaller or larger (depending on what kind of float you're using). That rounding error is what you see in your calculations.
You can probably see that rounding error more directly by doing calculations like
0.1+0.2-0.3or0.1*2-0.2. Some of them will actually give0, but a lot of them will give answers somewhere around the order ofE-16orE-17Note that this is also why using
==to compare floating point numbers is a bad idea. Numbers that mathematically should've been equal might be unequal inside the computer.