Lua math being very inaccurate with simple equations with floating points

I don’t know if this is a scripting issue, or a bug. But this issue is really stopping me from working on floating point values in my game.

As you can see in the image below i ran the following code print(1 - 0.9999), and the expected output should be 0.0001. But as shown in the image below, it returns 9.999999999... A completely inaccurate answer.


If anyone knows a solution to this, please let me know. Many thanks!

This is what is known as a floating point precision error, this occurs when the available number of bits to represent a number in the base 2 number system is too little to accurately represent the number.

This is both floating point errors and the way scientific notation is represented. The number outputted is actually:
9.9999999999989*10^-5 or 0.0000999…
Obviously, this isn’t 0.0001, but that’s just floating point numbers for you.