# Help with string-integer stuff?

So i wanna try something basically i want to make an integer system that you can decrease,increase,compare,multiply and divide using string.
the reason is to bypass math.huge() with 100% accuracy.
i have one working right now, but im kinda stuck on divide part

for multiply its pretty easy all i need to do is to call the add function multiple times

but for division i dont know how to do it.

How it work?

Basically it converts the string to integer string (lol)
something like this :

``````local val = "5"
local val2 = "10"
``````

first it convert the value to something like this

``````local val = "05"
local val2 = "10"
``````

then convert them to tables like this

``````local val = {"0" , "5"}
local val2 = {"1" , "0"}
``````

then just loop through the table and convert it to number and do some math stuff after that
that way it can bypass math.huge()

Script
``````local val = "1000"
local b = "259"

local function convert(a,b)
local lengthA = string.len(a)
local lengthB = string.len(b)

if lengthA > lengthB then
local difference = lengthA - lengthB
local newB = ""
for i = 1,difference do
newB = newB.."0"
end
newB = newB..b
b = newB
else
local difference = lengthB - lengthA
local newA = ""
for i = 1,difference do
newA = newA.."0"
end
newA = newA..a
a = newA
end
return a,b
end
local result = ""
local increaseNum = 0
local na,nb = convert(a,b)
na = string.reverse(na)
nb = string.reverse(nb)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local number = 0
local num = tonumber(v)
local numB = tonumber(splitB[i])
if num and numB then
if i == #splitA then
number = num + numB + increaseNum
result = tostring(number)..result
print("breaking on "..number)
break
end
local addition = num + numB + increaseNum
local tab = string.split(ts,"")
number = tonumber(tab[#tab])
print("number is "..tab[#tab])
local icn = ""
for i,v in pairs(tab) do
if i ~= #tab then
icn = icn..v
end
end
increaseNum = tonumber(icn)
else
increaseNum = 0
end
end
if number then
result = tostring(number)..result
end
end
return result
end
local function decrease(a,b)
local result = ""
local na,nb = convert(a,b)
na = string.reverse(na)
nb = string.reverse(nb)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local number = 0
local nex = splitA[i + 1]
local compareVal = splitB[i]
local num,numB
local numC = tonumber(splitB[i])
if nex then
num,numB = tonumber(v),tonumber(nex)
if (num - numC) < 0 then
numB -= 1
number = (num + 10) - numC
splitA[i + 1] = tostring(numB)
else
number = num - numC
end
else
num = tonumber(v)
number = num - numC
end
if number then
if i == #splitA then
if number ~= 0 then
result = tostring(number)..result
end
else
result = tostring(number)..result
end
end
end
return result
end
local function isMoreThan(a,b)
local result = ""
local na,nb = convert(a,b)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local num,numB = tonumber(v),tonumber(splitB[i])
if num and numB then
if num > numB then
return true
end
end
end
return false
end
local function isLessThan(a,b)
local result = ""
local na,nb = convert(a,b)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local num,numB = tonumber(v),tonumber(splitB[i])
if num and numB then
if num < numB then
return true
end
end
end
return false
end

print(decrease(val,b))
``````
2 Likes

Why would you need to bypass math.huge() at all? It’s something quintillion!

Converting strings to numbers and vice versa is easy enough. Just use tostring() and tonumber() functions (on strings and numbers respectively).

because i need to pass quintillion. thats why.
and i want to learn more, also lots of simulators have currencies that can pass math.huge() but theyre using math.log to pass it.which most people say to be not very accurate.

Store the currencies as string values and add them normally - it should still work fine due to coercion.

eg.

``````player.Leaderstats.Points.Value += 100
``````

With player.Leaderstats.Points.Value being a string value.
If not, trying using sets.

1 Like

If you want to do that, I’d reccomend checking out these forum posts:

The MoneyLib module in this might be useful for you (and maybe other stuff too)

RoStrap has a variety of libraries, BigNum is one of them and can help you deal with massive numbers

1 Like

A simple way to do that is to just get the “magnitude” of the number. Lets say the magnitude of 1234 is “3” and so 10^3 ≈ 1234 since 10^3 = 1000. Then index some suffix array with that magnitude of “3”

I created a “Number” library awhile ago, here is a snippet from it.

``````    function Number.Suffix(Number, Precision)
Precision = Precision or 0

local Suffixes = {
"", "K","M", "B", "T",
"Qa", "Qi", "Sx", "Sp",
"Oc", "No", "Dc", "Ud",
"Sxd", "Spd", "Ocd", "Vg",
"Uvg"
}

local Index = math.floor(math.log10(Number) / 3)
local Suffix = Suffixes[Index + 1]

Number = Number / (10 ^ (3 * Index))
Number = tostring(math.floor(Number * 10 ^ Precision) / 10 ^ Precision)

--//%.Precisionf%s also works. using tostring for simplicity

return Number .. Suffix
end
``````

and a few use cases,

``````print(Number.Suffix(123456)) --// outputs 123K
print(Number.Suffix(123456, 1)) --// outputs 123.4K
print(Number.Suffix(123456, 2)) --// outputs 123.45K
print(Number.Suffix(123456, 3)) --// outputs 123.456K
``````

Just store the actual number and do normal math with the number, but if you want to do any type of displaying then output the value from the `Number.Suffix` call with your input.

1 Like