Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my Gui's Size Changing From What I Wrote?

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!

3 comments

0

i think its the size of the GUI object without the border

0

I removed the border and it still prints the same thing

0

floating point inaccuracy (essentially those decimals can't be represented as a power of 2)

2 answers

✓ Accepted answer

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.

2 comments

0

Well, if you floor the number first, then divide it, that should fix it.

0

Thank you for the answer and the helpful comment! :D

I think that's just the nature of numbers in roblox. No way to fix it as far as i know.

2 comments

0

This is 'solved' type answer.

0

This is a bad answer. Have you never heard of floating points?

This discussion is preserved as it was. New answers, comments, and votes are closed.