Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by
Sulu710 142
4 years ago

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!

0
i think its the size of the GUI object without the border asdfghjk9019 225 — 4y
0
I removed the border and it still prints the same thing Sulu710 142 — 4y
0
floating point inaccuracy (essentially those decimals can't be represented as a power of 2) theking48989987 2147 — 4y

2 answers

Log in to vote
6
Answered by 4 years ago
Edited 4 years ago

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.

0
Well, if you floor the number first, then divide it, that should fix it. DeceptiveCaster 3761 — 4y
0
Thank you for the answer and the helpful comment! :D Sulu710 142 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

0
This is 'solved' type answer. ErtyPL 129 — 4y
0
This is a bad answer. Have you never heard of floating points? TheeDeathCaster 2368 — 4y

Answer this question