FormatNumber – Universal Number Formatting System for Roblox

Hi Developers!

I’m excited to share my FormatNumber system for Roblox, which makes displaying numbers in your games clean and professional — perfect for leaderstats, GUIs, or any other statistics.

The system features:

Automatic abbreviation of large numbers (K, M, B, T, Qa, Qi, up to Dc).

Removes unnecessary zeros after decimals: 12.00K → 12K, 12.50K → 12.5K.

Supports negative numbers.

Automatically chooses formatting: small numbers use commas, large numbers use abbreviations.

Example usage in a module:

local FormatNumber = require(game.ReplicatedStorage.FormatNumber)

print(FormatNumber.Format(987))
print(FormatNumber.Format(12345))
print(FormatNumber.Format(12300))
print(FormatNumber.Format(12000))
print(FormatNumber.Format(9876543))
print(FormatNumber.Format(1234567890123))
print(FormatNumber.Format(-1234567890123))
print(FormatNumber.Format(1234567890123456))

Example integration with leaderstats:

local Players = game:GetService("Players")
local FormatNumber = require(game.ReplicatedStorage:WaitForChild("FormatNumber"))

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Value = 1234567
	Coins.Parent = leaderstats

	Coins:GetPropertyChangedSignal("Value"):Connect(function()
		Coins.Value = FormatNumber.Format(Coins.Value)
	end)
end)

This system is perfect for any game with currency, points, experience, or other stats. It makes your UI clean, readable, and professional.

Here is FormatNumber (ModuleScript)

local FormatNumber = {}

local function addCommas(number)
	local formatted = tostring(number)
	local k
	while true do
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if k == 0 then break end
	end
	return formatted
end


local suffixes = {
	"", "K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc"
}

local function abbreviate(number)
	local index = 1
	local num = math.abs(number) * 1.0
	while num >= 1000 and index < #suffixes do
		num = num / 1000
		index = index + 1
	end

	local formatted = string.format("%.2f", num)

	formatted = string.gsub(formatted, "%.00$", "")
	formatted = string.gsub(formatted, "(%.%d)0$", "%1")

	if number < 0 then
		formatted = "-" .. formatted
	end

	return formatted .. suffixes[index]
end

function FormatNumber.Format(number)
	if math.abs(number) >= 1000 then
		return abbreviate(number)
	else
		return addCommas(number)
	end
end

return FormatNumber

Create a ModuleScript in ReplicatedStorage

image

Thank you very much for reading my post! :heart:

10 Likes

Why only up to a decillion? Come on, give me formatting for my quinquinquagintaquingentillion!

hi i have no idea what this does? can it make robux??