Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my NumberValue messing up at 100 Trillion?

Asked by
sad_eyez 162
6 years ago

I am trying to make a script to go up to like Quadrillion, and Quintilian but it messes up at 100 Trillion, can anyone help me with this?

Code:

local money = script.Parent.Parent["Money"]


while wait() do

    local val = math.abs(money.Value)
    local str = tostring(val)


    -- Trillions
    if val >=1e+14 then
        script.Parent.Text = string.sub(str, 1,3).."."..string.sub(str, 4,4).."T+"
    elseif val >=1e+13 then
        script.Parent.Text = string.sub(str, 1,2).."."..string.sub(str, 3,3).."T+"
    elseif val >=1e+12 then
        script.Parent.Text = string.sub(str, 1,1).."."..string.sub(str, 2,2).."T+"
    -- Billions
    elseif val >=1e+11 then
        script.Parent.Text = string.sub(str, 1,3).."."..string.sub(str, 3,3).."B+"
    elseif val >=1e+10 then
        script.Parent.Text = string.sub(str, 1,2).."."..string.sub(str, 3,3).."B+"
    elseif val >=1e+9 then
        script.Parent.Text = string.sub(str, 1,1).."."..string.sub(str, 2,2).."B+"
    -- Millions
    elseif val >=1e+8 then
        script.Parent.Text = string.sub(str, 1,3).."."..string.sub(str, 3,3).."M+"
    elseif val >=1e+7 then
        script.Parent.Text = string.sub(str, 1,2).."."..string.sub(str, 3,3).."M+"
    elseif val >=1e+6 then
        script.Parent.Text = string.sub(str, 1,1).."."..string.sub(str, 2,2).."M+"
    -- Thousands
    elseif val >=1e+5 then
        script.Parent.Text = string.sub(str, 1,3).."."..string.sub(str, 3,3).."M+"
    elseif val >=1e+4 then
        script.Parent.Text = string.sub(str, 1,2).."."..string.sub(str, 3,3).."M+"
    elseif val >=1e+3 then
        script.Parent.Text = string.sub(str, 1,1).."."..string.sub(str, 2,2).."M+"
    -- Hundreds
    elseif val >=0 then
        script.Parent.Text = str
    end
end

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

ROBLOX uses a 32-bit platform which means ROBLOX Lua cannot hold numbers larger than 4,294,967,295. You are experiencing an integer overflow and there's no way around it as far as I know. Here is the Wikipedia entry if you want to understand what an Integer Overflow is https://en.wikipedia.org/wiki/Integer_overflow . Why do you even need that much money anyway?

0
It's actually half of that, since you have to account for negatives too. The range is -2147483648 to 2147483647. fredfishy 833 — 6y
0
Oh yeah, you're right. Thanks for correcting me... Either way, still stuck at Trillions. Encladeus 31 — 6y
0
Also the range of an integer doesn't have much to do with whether a program is 32 bit or 64 bit. That has more to do with how many locations in memory a program can address. It's just that the de-facto standard seems to be that a stadard integer is 32 bits. (Can anybody point me to an actual IEEE or similar standard on this?) fredfishy 833 — 6y
0
But how does it work in Miner's Haven? There are numbers much larger than trillions! Lolnox 47 — 6y
Ad

Answer this question