My Image Gui's size is x-scale 0.06 and y-scale 0.062, with no offset values (or in UDim {0.06, 0}, {0.062, 0}
). The problem is, when I try to get the size in a script, the size is not that. Even when I run a function in the command bar to print the Gui's size, it comes out as {0.0599999987, 0}, {0.061999999, 0}
. It says the same thing if I try to print the Gui's size from a script. I've tried rewriting the size in the properties tab as well as changing it with a command, but no matter what I try it always prints as {0.0599999987, 0}, {0.061999999, 0}
. This doesn't appear to be happening with any of my other Gui's so I don't know what is happening. Thank you for reading this and I hope you can help!
In almost all programming languages (if not most, then every language) there is a type of runtime "error" that can occur called roundoff. A roundoff error is when the compiler gives you the number it stored in binary instead of the actual number you gave it. (More specifically, a roundoff error is the difference between the computation of the given numerical value and the actual numerical value.) That number is extremely close to the one you gave it, but it isn't the one you gave it.
This usually occurs with floating-point numbers, more commonly known as decimals. When you assign something to a decimal, Lua uses the number it created in binary to try to match the number given. Lua rounds off the number and gives you an unnecessary amount of decimal places represented by the number given that is, once again, really close to the one given, but not exactly the same number.
Lua is not the only language that can experience this runtime error. Quite literally every programming language can round off a floating-point number.
If you're wondering how to fix it, you can try flooring a number using math.floor()
then dividing that number to get the decimal you want.
I think that's just the nature of numbers in roblox. No way to fix it as far as i know.