At what number does Roblox use scientific notation?

I couldn’t find any info on this on the DevForum, or on the DevHub. Any help is appreciated!

3 Likes

Why you need it to know? Only for curiosity or else?

I’m pretty sure it’s at math.huge()

Edit: here’s a previous thread with the same query

@Secretum_Flamma i found a page: Scientific notation - Wikipedia. I found this page in the Roblox Wiki: Numbers | Documentation - Roblox Creator Hub.

Scientific notation — Write a decimal number followed by e or e+, then an integer to raise the decimal number to a power of 10. For instance, 12e3 is 12 × 10^3 (12,000).

This is wrong, math.huge represents the largest number that can be used in Lua. Therefore, it is bigger than any number with a defined value.


You could solve this fairly easily by doing:

for i = 0, 20 do
    print(i, "\t", 10 ^ i)
end

and seeing which is the first to be truncated.

When I run it, this is the output I get:

0 	 1
1 	 10
2 	 100
3 	 1000
4 	 10000
5 	 100000
6 	 1000000
7 	 10000000
8 	 100000000
9 	 1000000000
10 	 10000000000
11 	 100000000000
12 	 1000000000000
13 	 10000000000000
14 	 1e+14
15 	 1e+15
16 	 1e+16
17 	 1e+17
18 	 1e+18
19 	 1e+19
20 	 1e+20
9 Likes

I see, I got 1e+20. This maybe the smallest number that Roblox will use scientific notation.
And this only works in NumberValue, if you use IntValue will get a strange number without
using scientific notation.
Largest IntValue possible = 9223372036854775807
Smallest IntValue possible = -9223372036854775808

1 Like

Typing into NumberValue will be different.

The original post does not mention a NumberValue, therefore I will assume they didn’t mean that.

I see, maybe there are two solutions for this topic.

tostring(n) switches to big e notation after n ≥ 1e14. You can keep the digits using ("%f"):format(n), e.g. print(("%f"):format(2^1023))

89884656743115795386465259539451236680898848947115328636715040578866337902750481566354238661203768010560056939935696678829394884407208311246423715319737062188883946712432742638151109800623047059726541476042502884419075341171231440736956555270413618581675255342293149119973622969239858152417678164812112068608.000000

although not all of the digits will always be correct given the limits of precision.

2 Likes

Roblox just uses sprintf for number formatting, same as what vanilla Lua does. Lua’s default format specifier is “%.14g”, that’s where the 14 digits come from.

If you really want to know in complete detail how the string formatting works It’s here in section 7.21.6.1 of the C spec

5 Likes

It’s because I’m using a system that allows for numbers much larger than the regular limit of 1.6e+308, courtesy of this post, and 1waffle1.

If I know the number that Roblox uses scientific notation, I can set the exponent to zero, until I hit that number.

1 Like