Abbreviating numbers

What do I do to make the currency look the same in both the GUI and the table?

----------Script GUI:----------

while wait(0.1)do

script.Parent.Text=game.Players.LocalPlayer.leaderstats.Bloins.Value…" Bloins"

end

----------Script Table:----------

local stat = “Bloins”

local startamount = 0

local DataStore = game:GetService(“DataStoreService”)

local ds = DataStore:GetDataStore(“LeaderStatSave”)

game.Players.PlayerAdded:connect(function(player)

local leader = Instance.new(“Folder”,player)

leader.Name = “leaderstats”

local Bloins = Instance.new(“IntValue”,leader)

Bloins.Name = stat

Bloins.Value = ds:GetAsync(player.UserId) or startamount

ds:SetAsync(player.UserId, Bloins.Value)

Bloins.Changed:connect(function()

ds:SetAsync(player.UserId, Bloins.Value)

end)

end)

game.Players.PlayerRemoving:connect(function(player)

ds:SetAsync(player.UserId, player.leaderstats.Bloins.Value)

end)

There are multiple ways to do that,

Here is a very simple one:

local abbreviations = { -- our abbreviations
	N = 10^30;
	O = 10^27;
	Sp = 10^24;
	Sx = 10^21;
	Qn = 10^18;
	Qd = 10^15;
	T = 10^12;
	B = 10^9;
	M = 10^6;
	K = 10^3
}


function abbreviateNums(number)

	local abbreviatedNum = number -- our number that we want to abbreviate
	local abbreviationChosen = 0 -- helpful variable

	for abbreviation, num in pairs(abbreviations) do

		if number >= num and num > abbreviationChosen then

			local shortNum = number / num
			local intNum = math.floor(shortNum)

			abbreviatedNum = tostring(intNum) .. abbreviation .. "+"
			abbreviationChosen = num
		end
	end

	return abbreviatedNum -- we return it, so that we could use it more.
end

To call it, you can simply do:

script.Parent.Text = abbreviateNums(game.Players.LocalPlayer:WaitForChild("leaderstats").Bloins.Value).." Bloins"
1 Like

Thanks, but isn’t there some other way to make it look like the table or at least show if you have 1,500 and not 1k?

Yes, there are :

just remove the math.floor() and then yea

local suffixes = {"K", "M", "B", "T", "Q"}

function roundNumber(number)
	local finalNr = math.floor((((number/1000^(math.floor(math.log(number, 1e3))))*100)+0.5)) /100 .. (suffixes[math.floor(math.log(number, 1e3))] or "")
	return finalNr
end

then just do

roundNumber(money) --money is your currency so like Bloins in your case

or

textlabel.Text = tostring(roundNumber(money))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.