Specific number formatter

So I basically want to make a number formatter that formats differently: if the player has 100 million cash, it should not have a decimal and should look like “100M”; if the player has 10 million cash, it should have one decimal place if the decimal is not zero and should look like “10M(10,000,001)”, or "72.9M(72,947,199); if the player has less than 10 million cash and more than a million, it should have two decimal places or less if the values of the decimal is 0, and it should look like this: “1.8M(1,808,277)”, “1.09M(1,092,746)”, “3.71M(3,719,272)”, etc. (I picked the numbers randomly for the example)

This is the furthest I have gotten into:

local player = game.Players.LocalPlayer
local value = player:WaitForChild("leaderstats"):WaitForChild("Coins")

local Abbreviations = {
	"";
	"K";
	"M";
	"B";
	"T";
}

local function AbbreviateNumber(Number)
	for i = 1, #Abbreviations do
		if Number < 10 ^ (i * 3) then
			if Abbreviations[i] == "∞" then
				return "∞"
			else
				return math.floor(Number / ((10 ^ ((i-1) * 3)) / 100)) / (100) .. Abbreviations[i]
			end
		elseif tostring(Number) == "inf" then
			return "∞"
		end
	end
end

script.Parent.Text = AbbreviateNumber(value.Value)

value.Changed:Connect(function()
	script.Parent.Text = AbbreviateNumber(value.Value)
end)

and does not get what I want. Any help appreciated.

1 Like

This module does what you need with more customization

1 Like

where do i get it? i might have went to the wrong place for it

You can get it by downloading it under the category “Files” > “Current Version”.

test or file? are they the same?

Download file, I assume “Test” is an unstable version.

1 Like

it opened in a new game. how do i get it to the game im working on?

NEVER MIND! I used something else and solved the problem. Thanks.

1 Like

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