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

How would I make these large numbers easier to read?

Asked by 6 years ago

:I'm making a clicker game where you make in-game currency, and the numbers will be getting quite high, in the billions or so. Is there any way I could use symbols to account for some of the numbers in order to make them more readable? For instance, if we had 21,500,000,000 (21.5 Billion), it would say something like 21.5B? I don't have much experience with getting specific characters in values and such so how would this be achieved?

1 answer

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

I just found this. Not sure if it works.

function ConvertShort(Filter_Num)
    local x = tostring(Filter_Num) -- This is the number you want changed
    if #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

To use this, just put this anywhere below the function in your script when you need it. It makes a variable with the new form. local ShortCash = ConvertShort(Your number goes here)

0
Thanks, but how exactly could I use this in my script? It looks fairly confusing and I'm not sure what to change to make it compatible. EnderGamer358 79 — 6y
0
Does that help? Crazycat4360 115 — 6y
0
I'll try it real quick, just a sec... EnderGamer358 79 — 6y
0
I tried it and it worked to some extent, but when I put in the integer I mentioned earlier (21.5B), it printed it as 21.0B, so it isn't reading the decimal correctly. EnderGamer358 79 — 6y
View all comments (6 more)
0
Did you put it in like 21500000000? Crazycat4360 115 — 6y
0
Yes, I put in that number, for some reason the script isn't reading the decimal correctly. EnderGamer358 79 — 6y
0
Im doing two extra lines of code at the end: One to call the function and the other to print the simplified number. Neither of them are the issue as far as I know. EnderGamer358 79 — 6y
0
I just did some fiddling around and figured out if I try doing an integer in the millions or thousands the decimal prints fine, so somewhere in the beginning of the function there's an error EnderGamer358 79 — 6y
0
Finally figured out the issue, the 7's in line 5 were supposed to be 8's, as soon as I did this the decimals worked fine. Thanks for the base script EnderGamer358 79 — 6y
0
Sweet! Glad it worked. Have a good day :) Crazycat4360 115 — 6y
Ad

Answer this question