How can i handle scientific numbers?

im trying to make a shop with expensive items but when working with big numbers roblox uses scientific numbers like 1e+15 but when i use these roblox gets the maths wrong. is there any way i can avoid this?

print(10000000000000000000000-9999999999999999999999)

Output: 0 but it should be 1

Most likely some internal rounding issue, but why’d you need to do this precise math anyway? If you want 1, just type 1.

im using this for a shop so i need it to get the right values. because right now it kinda rounds the numbers because of the scientific numbers

This is probably due to the integer limit, you should instead to it with powers like 10^6 etc.

1 Like

I’d recommend using smaller numbers in your code, and when displaying them, multiply them so that they seem big to the user.

Another solution would just not to use that big numbers in the first place, since in most instances they are fairly unnecessary, but that’s really up to your preference.

You can also use a library that handles big numbers, like BigInteger for example.

another option is to add another currency into your game

so lets say 1,000,000,000 coins = 1 goldbar

and there is a banker that will trade 1,000,000,000 coins into 1 gold bar or 1 gold bar back to 1,000,000,000 coins this could also be done automatically as you receive coins without the need of a banker

so if 1 gold bar has a value of 1,000,000,000 coins

1,000,000,000 gold bars has a value of 1,000,000,000,000,000,000 coins

And then your expensive shop could ask for goldbars instead of coins

you can also take this another level so

1,000,000,000 gold bars = 1 diamond
1 diamond has a value of 1,000,000,000,000,000,000 coins

3 Likes

There is an appropriate use case for large numbers in code but I do not think your shop’s item values is one of them. You should probably take a look at your scaling or, as the above feedback mentions, consider dividing into another currency with a larger valuation after a certain threshold.

As for the number itself it’s possible to represent it without exponential notation:

print(string.format("10000000000000000000000", "%.f"))
1 Like