Large Numbers Gets Randomly Decreased

So i found out that a number thats bigger then 1e+22 will be decreased in a weird way, example 1e+23 will be 99999999999999991611392.0, and this is rlly weird since i cant find any topics talking about this, can anyone explain this? and how can i prevent/avoid this problem?

number = 100000000000000000000000
print(string.format("%.1f",math.floor (number)))
--->99999999999999991611392.0

I suggest you use this link, i’m not entirely sure but I assume this is what’s happening.
Edit: typically I don’t think roblox can handle exceptionally large numbers and that’s why it’s decreasing,
because it sets your number to a type that has a limit on digits. Might be overflow? Might be engine design?

That’s a floating precision error, it happens certain times, that’s why the
if number == desirednumber then
isn’t totally reliable.EDIT: For certain times I mean with really small and really big numbers.

so is there no way for me to change the format of the number will it have to be float?

if you need to store an incredibly large number, I suggest storing it in the form of multiple numbers and displaying it seperately.

EDIT: It exponentially increases the amount of digits your number can possess.
For example, you have
local number = {[1]=100,[2]=205,[3]=300 }
at least, that’s something like how i’d do it, because I could iterate through it

Also JCN, did you read the link I said? I already explained floating point inaccuracies.

For avoiding that you could divide the number in scientific notation.

yep i see, thx alot for both of u replying

I do suggest watching this video.

the conclusion of this video: it’s hard to get rid of those floating numbers.
Note, IntValues/math.floor, has a max limit.

What you instead can do is turn the number into a string (with tostring ()), look for the “.” once you found that check if the string after that is a 5+ by turning the decimal back to a number (with tonumber ()), I suggest cutting the rest around it up (e.g. by using string.sub ())

1 Like

yeh i thought of that too, so im doing that rn :smiley:

1 Like