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

How do I make short form numbers?

Asked by 5 years ago

You know-how in all Roblox simulator games the numbers are compressed and turned into instead of 10,000 its 10K and instead of 1,000,0000 its 1M. How can I implement that into my script?

local plr = game.Players.LocalPlayer
local value = plr.Character:WaitForChild("LeftHand").Drinkies.Part.Value
value.Changed:Connect(function()
    if value.Value == value.Parent.MaxValue.Value then
        script.Parent.TextLabel.Text = value.Value.."/"..value.Parent.MaxValue.Value
        script.Parent.Parent.FullBag.Visible = true
    else
        script.Parent.TextLabel.Text = value.Value.."/"..value.Parent.MaxValue.Value
    end
end)
0
Your formatting function will depend on how much precision you want to keep. For example, does 12345 become 12K or 12.3K or 12.35K, etc.? EmilyBendsSpace 1025 — 5y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

It's really simple, all you need to do is check if it is divisible by a thousand/million/billion and then handle it accordingly:

function check(num)
    if (num/1000000)>1 then
        print("$"..num/1000000 .."M")
    elseif (num/1000)>1 then
        print("$"..num/1000 .."K")
    end
end

check(2000000)

Your number would be the num, but in my case, it would turn that 2000000 into $2M. Also take note that you will want to check if it is larger first, if I switched those, it would print $2000K.

If this answers your question, then mark it as the accepted solution.

Ad

Answer this question