So I think I basically understand how floating-point works and why we can't have "precise" results for some operations.
I got confused by this SO-question, where @MikeMüller suggests rounding.
My understanding is the following.
If we write decimal places it would look like this:
1000 100 10 1 . 1/10 1/100 1/1000
It would look like this in binary:
8 4 2 1 . 1/2 1/4 1/8
So we store 0.5 or 0.25 or 0.125 precisely in memory but not e.g. 0.3
So why does python output the following:
print(0.1)
print(0.2)
print(0.3)
print(0.1 + 0.2)
>>>0.1
>>>0.2
>>>0.3
>>>0.30000000000000004
I think it should output
>>>0.1
>>>0.2
>>>0.30000000000000004
>>>0.30000000000000004
Where am I wrong?
My Question is NOT a duplicate of Is floating point math broken? because OP does not understand why 0.1+0.2 != 0.3. This is not topic of my question!