Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make short form numbers?

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)

2 comments

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.?

1 answer

✓ Accepted answer

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.

2 comments

0

Wow! Thanks a lot!

This discussion is preserved as it was. New answers, comments, and votes are closed.