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

How do you abbreviate your money value if it is in scientific notation?

Asked by 4 years ago

I put this code in a module script and referenced to it in other scripts, and it works, but it only go up to 100T then it goes all funky and says like 1000000000000k or something. Can someone please help.

local abbreviatednumber = {}
local abb = {
    k = 4,
    M = 7,
    B = 10,
    T = 13,
    Qa = 16,

}
    function abbreviatednumber:abb(x)
            local text = tostring(math.floor(x))
    local chosenabb
    for abbreviations, digits in pairs(abb) do
        if #text >= digits and #text < (digits + 3) then
            chosenabb = abbreviations
            break
        end
    end
    if chosenabb then
        local digits = abb[chosenabb]

        local rounded = math.floor(x / 10 ^ (digits - 2)) * 10 ^ (digits - 2)

        text = string.format("%.1f", rounded / 10 ^ (digits - 1))..chosenabb

    else
        text = x
    end
    return text
    end

return abbreviatednumber

Answer this question