We covered this on GitHub. It is something of a FAQ and is general to all programming languages. It's also caused grief to the writers of spreadsheets. Users howl because they see errors so spreadsheets have all sorts of hacks to avoid frightening the horses. So here is my attempt at explaining something which first baffled me in ~1969.
Floats are data types which cannot be represented perfectly in any finite number of binary bits. This is obvious in the case of numbers like π or e. The result of 1/3 requires an infinite number of bits to represent it. Representing floats in 32 or 64 bits will therefore often produce results with evident imprecision and sometimes this is surprising.
If I issue
Code: Select all
the number is being correctly rounded to two decimal places, but the resultant value of 65.51 cannot precisely be represented in 64 bits. Hence the error in the 14th decimal place.
As Kevin says, this can be worked round using string formatting but there are other consequences. This link
is a simple guide to some practical programming consequences. A more academic exposition is here