Hey everyone, I was doing some work with percentages and I noticed my code was outputting unexpected numbers.
As you can see when I use math.floor on A it says the result is 9, and when I use it on the number 10 (which is the same as A) the result then changes to the expected 10.
This is because math.floor always rounds down and the math operation you’re doing is creating a floating point error, which is a slight deviation from the expected number. math.floor won’t round up even in the slightest.
A isn’t actually 10. Yes it’s a floating point error. Any math you do using fractions should always be rounded using the classic math.floor( answer + 0.5 ) if you want it to be a perfect integer.
It’s because 0.9 and 0.1 cannot be perfectly represented, but Roblox will display 9.999999 as 10 once it gets to a certain number of decimal places as it’s not practical to show all of them.
Edit: if you wish to prove this to yourself, try this,