Strange decimals, might be urgent issue

I noticed that, sometimes when I move or resize a part, it seems to get strange and rather small decimals.
I thought it was the plugin I used, eventually.

But now I made this for loop, and used print() to see what it showed. And sadly, even there those decimals occurred.
Here are screenshots of pieces code related to it:


Element = "Necromancy"

and

stance = "Regular"

in this case.

And this is the output:


As the script stated, some for loops should go up/down with 0.1 each and some with 0.05. But instead it comes up with these out-of-nowhere decimals for some reason.

I mean, I can math.floor() or math.ceil() them, but I thought I’d report it as it doesn’t just occur in scripts.
I might’ve made some errors in the script, but I noticed this whilst fixing them. So pardon these errors.

http://lua-users.org/wiki/FloatingPoint

Unfortunately it’s a caveat of lua. This isn’t a roblox exclusive issue.

1 Like

Is there a way to get around it? It’s rather annoying.
Like, without using math.floor() or math.ceil()?

This is off-topic, but I’d like to mention that the smallest amount of time that the function wait(t) can wait is 1/30th of a second, which is .033 repeating. When you give it a smaller value, it will default to .033.

4 Likes

Is the problem that the end transparency is not exactly what you need it to be?

If the issue is that you don’t like the ugly decimals that are coming up while it’s tweening – I feel like that is a useless thing to fix.

If it’s the end transparency, why don’t you just set it after the for loops are complete?

1 Like

Oh! Let me try putting that on a different value, if that makes a difference?

Well, it’s not much of an issue related to this script. It’s generally, also for resizing parts.
Though, I do dislike the decimals lol.

I don’t think there is a fix for this then, no.

1 Like

Agh, ok. Thanks.

No, the wait(t) function has no bearing on the floating-point imprecision problem that you are noticing. I just wanted to bring this up, since you are using it in a forloop, you might be expecting it to be waiting a lot less time than it is actually waiting.

1 Like

Ohh! Ok, thanks for mentioning :slight_smile:
I do hope ROBLOX’s able to fix the resizing somehow though. I do use SBS (Studio Build Suite) as resizer, so I cannot judge about the built-in resizer. Just wanted to make sure everyone was aware.

This isn’t really something that needs fixing. This is just based on how floating point numbers are represented internally, using more bits would increase the precision but it would be arguably wasteful because the difference for small numbers would be negligible.

If you are interested in finding out how floating point numbers are represented and why there is a loss in precision then there is a lot more information on Wikipedia.

Anyway, if you don’t want to see the smaller decimals you can just do something like
print(string.format("%.3f", v[transparency]))

2 Likes

Well, I mean it’s rather difficult to make unions if something’s not precise like that. At least, I have tested that the same building with those decimals has more troubles becoming a union than without those decimals.

I didn’t notice this a while ago, hence my concerns.

But I’ve understood. :smiley: Thanks for the help everyone!