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

Currency Conversion Script Not Working?

Asked by 5 years ago
Edited 5 years ago

So I have a currency convert script where if it goes above a certain number of 0's then it converts to 1M+ for example. It converts up to 99T+ but then when the NumberValue reaches 100T it displays 1e.+K+ and then the 1 goes to 2, etc. when higher. My Code:

function module:ConvertShort(Filter_Num)
    local x = tostring(Filter_Num)
    if #x>=19 then
        local important = (#x-18)
        return x:sub(0,(important))..".."..(x:sub(#x-15,(#x-15))).."Qn+"
    elseif #x>=16 then
        local important = (#x-15)
        return x:sub(0,(important))..".."..(x:sub(#x-13,(#x-13))).."Q+"
    elseif #x>=13 then
        local important = (#x-12)
        return x:sub(0,(important)).."."..(x:sub(#x-10,(#x-10))).."T+"
    elseif #x>=10 then
        local important = (#x-9)
        return x:sub(0,(important)).."."..(x:sub(#x-7,(#x-7))).."B+"
    elseif #x>= 7 then
        local important = (#x-6)
        return x:sub(0,(important)).."."..(x:sub(#x-5,(#x-5))).."M+"
    elseif #x>=4 then
        return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
    else
        return Filter_Num
    end
end

I'm not really sure what is wrong here. If someone could please help me that would be great! Also, I do have my leaderboard script that has the function activate when displaying the value.

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

ROBLOX starts writing numbers in scientific notation after a certain point.

You'd format the string to write it differently. See this example to see what I mean:

i = 1

while(wait(.5)) do
     i = i*10
    print(i)
    print(string.format("%d",tostring(i)))
end


Just remember after a certain point your number will overflow and become negative.

Ad

Answer this question