Roblox’s IntValues can only seem to hold numbers smaller than 9223372036854775807
When converting a large number to a string, it will be shown via scientific notation (1e+n)
This is a problem I faced a long time ago, and I’m sure there are plenty of developers (both experienced and inexperienced) that will find themselves with the same problem.
How to solve it:
Use strings.
StringValues can hold 200,000 characters. I can’t exactly show you how big that really is, but here is something:
- 1 billion = 1000000000 (10 characters)
- 1 nonillion = 1000000000000000000000000000000 (31 characters)
So, you can probably imagine how big a number of 200,000 characters is
How to use this in your code:
‘string numbers’ can be used in your code, by using the built-in tonumber()
function.
This will convert any string into an integer, as long as it is able to do so.
(For instance, tonumber(“abc”) would not work, as ‘abc’ is not an integer)
Is this even useful?:
That’s debatable. In my opinion, yes! 200,000 characters worth of integer is a lot.
This is especially useful for simulators and other games that handle large amounts of numbers.
Before I finish this post, here is a number abbreviation function I made:
local function abbreviate(num)
local suffixes = {"K","M","B","T","qd","Qn","sx","Sp","O","N","de","Ud","DD","tdD","qdD","QnD","sxD","SpD","OcD","NvD","Vgn","UVg","DVg","TVg","qtV","QnV","SeV","SPG","OVG","NVG"}
local amnt = math.floor(((#num)-1)/3)
local remove = 3*amnt
if suffixes [amnt] then
return string.sub(tostring(num),1,(#num)-remove)..suffixes [amnt]
else
return num
end
end
With the suffixes I provided, it can go as far as 999NVG (93 characters!)
To use it, simply call the function, with the argument of a ‘string number’:
abbreviate("1000000")
= “1M”
I hope some of you will find this useful. There are plenty of different ways to handle large numbers in your code, this is just one of them.