Output not printing in correct order, or at all sometimes

Reproduction Steps
Insert a UIScale object, and then with a script, set its Scale property to 0. Then do print(UIScale.Scale)

Expected Behavior
The print should return 0

Frame.UIScale.Scale = 0
print(Frame.UIScale.Scale)

Actual Behavior
I get 1.0000000116861e-07 for some reason

Workaround
I tried to do math.floor(0), did not change fix however

Issue Area: Studio
Issue Type: Other
Impact: High
Frequency: Constantly
Date First Experienced: 2021-09-07 00:09:00 (+08:00)
Date Last Experienced: 2021-09-09 00:09:00 (+08:00)

1 Like

That’s basically 0. Notice the e-07? That means * 10^-7, so your number is actually 0.0000001... in value.

Not really a bug, just how floating numbers work. Although it is slightly strange that the Scale cannot properly model 0 since that can normally be represented perfectly as a floating point, you should expect inaccuracies like this when working with floating point numbers.

Look up https://floating-point-gui.de/

2 Likes

So do I have to do

if UIScale.Scale <= 0.0000001 then

??

1 Like

──────────────────────────────────────────────────
β”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€
β”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€β”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€
β”€β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€
β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”€β”€β”€β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€
β”€β”€β”€β”€β”€β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€
β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€
β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€
β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€
β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ”€
β”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β”€β”€β”€β”€β”€β”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€
──────────────────────────────────────────────────

5 Likes

For float comparison that is always a good idea yeah. You compare against some epsilon (small number) and if your value is within epsilon of some other value, you assume they are equal.

eps = 0.0001 should be fine for most use cases.

This is not unique to Roblox – everyone that deals with floating point comparisons anywhere in their code base needs to do this.

1 Like

Sounds like this isn’t a Roblox issue, closing it out. Huge thanks for the report, @NinjoOnline