When I tried doing “1-0.8” it returned something like 1.999999996…?
This means it isn’t going to be efficient with my armor bar UI, since every armor I make or change their values, I’ll have to update the if statements in the script too. I did something where I asked the value and depending on that the number would be what I would think 1-(0.8 or any other protection values) would be.
This is called a floating-point error, the precision of decimals are not super accurate and are most of the times resulting like that. It’s not a Roblox-niche thing, but it is a computer-related issue that stems from using binary systems to try to represent decimals.
You can try to mitigate the problem by using rounding, truncating, etc. Anything that actually fits the box.
4 Likes
yeah I was thinking of turning the numbers into strings, then getting the 3rd character (the decimal) then minus it by 10. I haven’t tried this yet but I will soon
Edit: Just minus 10 from tonumber(string.sub(tostring(decimal),3,3)) and you get the number it’d be if it was a decimal, except you have to use that for comparing the index in a for loop, instead of what I was doing which was the value