Dividing a huge number by 2 is causing some issues

There is an interesting problem where when I divide a large number such as this one: 3715113113116158154116119113141581861331631 by 2… here is what it turns into…

1.8575565565581e+42, So first of all, the HUGE NUMBER that I specified above divided by 2 is (Obviously) not 1.8575565565581e+42, is there anything I can do to fix this?

Plus, if I multiply the number by 2, it turns into 3.7151131131162e+42 instead of 3715113113116158154116119113141581861331631, is there any way I can accurately, and properly divide, and multiply huge numbers like this without these problems?

I understand there are barely no use cases for this, but I still need help!

1 Like

In short, experimenting with huge numbers can cause some issues. An Int64 data type will result in the number range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Any numbers outside of that range will cause some errors to occur. In your case, your number is so huge that it causes Roblox to display the number in scientific notation. You can read more here at: Numbers | Documentation - Roblox Creator Hub.

1.8575565565581e+42 actually is correct. The e+42 is short-hand for * 10 ^ 42, meaning it’s 1.8575565565581 * 10 ^ 42 which is 1857556556558100000000000000000000000000000.

1 Like

Is there any way I can detect what is past that ‘e’, and use an algorithm to remove it?

Edit: Nvm, i’m just probably too lazy, I can probably figure it out myself i bet.

1 Like

This is because the number is getting converted to scientific notation. The way you would want to view the number is in fixed notation.

I know there is an easy way to change this in C++, but I havent found anything as easy in Lua.

Why does lua / roblox-lua do that though? It would be way better to not have that happen when I divide a Huge Number by 2.

You can’t. All numbers on Roblox are “double-precision floating-point”, meaning they are 64 bits of data. Because of that limit, it has to simplify to scientific notation. It’s showing you all of the data it has.

1 Like

Soo… Its just 100% impossible, unless roblox makes some changes with their numbers, and change that limit?

Here’s some code I’ve found online:

function get_real_number(r)
	return string.format("%f", r)
end

x = 300030003000300030003000300030003000300

print(x)
print(get_real_number(x))

The first print says: 3.000300030003e+38

Where as the second print prints the actual given number.

1 Like

It’s possible but not natively. You’d need to import a library like BigNum. https://github.com/ennorehling/euler/blob/master/BigNum.lua

EDIT: This is if you want to perform operations on large numbers. I think you just want to display them.