Put simply: computers don't have infinite memory, so they can only use so many bits to store a number. If the number has too many decimals, they will get cut off somewhere, and it just so happens that 0.4 (two fifth) in binary representation has more decimals than it cans save; so after cutting them off, you're left with 0.399999something, which print
is smart enough to print as 0.4, but if you floor()
it, it gets rounded down without mercy, leading to the results you see.
Also please note that you could have just googled this; it's one of the most common questions in programming ;)
As an example, try this:
string.format("%f", 20.4*100)
--> 2040.000000
string.format("%0.20f", 20.4*100)
--> 2039.99999999999977262632