Is there a way to get a number with more than 14 digits?

This has been on my mind lately, is there a way you can extend certain digits. For example, printing a few more digits of pi

print(3.141592653589793238) -- rounds to the nearest 14th decimal place,  3.141592653589793

or numbers not converting into scientific notation when too large

print(1e100) -- should be 1 and 100 zeros following, and not 1.e+100

I know its more of a luau problem, but I was curious if there was a work around

As for the first - this is not possible with Luau VM “number” data type due to the limitation of IEEE 754 double precision floating point format and machines in general. You can try to implement your own “real” (which will be rational due to the limitation of machines) data type instead.

For the second you can just split the significand and exponent (the e) and move/strip the decimal marker to certain position (.) with string manipulation and fill some 0s where necessary - this should be trivial to implement. (or alternatively use string.format's %f specifier - though the value is rounded to certain fractional digits so it may not be exactly what you’re looking for)

1 Like