Awesome, that sorted out the division issue, huge thanks!
However, I’m still getting the strange recurring decimals, even with 1.0 - 0.8 - however, this isn’t causing any problems for me at the moment, and judging by how close they are to the true value, it may never be an issue.
Hi there, what’s you’re running into here is caused by the fact that floating point numbers are inaccurate by design. This is due to them occupying a limited size in memory, so they can’t represent every possible decimal number and therefore have limited precision.
As @samaaron explains, all computer floating point numbers have a finite precision. The default Float is not decimal— it is binary— and has a precision of 53 bits (nearly 16 decimal digits). That should really be enough for our purposes, but it is still possible to manipulate them incorrectly in a calculation, causing loss of precision, or make invalid comparisons like
a = 0.15 + 0.15
b = 0.1 + 0.2
It is not a problem with the numbers; you just have to use them correctly.
If you really need decimal numbers instead of binary, you can do something like