Skip to content

Number formatter

Try any number to see the short label, then copy the Luau function that produces it.

1.5M instead of 1500000 on a leaderboard · Checked October 16, 2026

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

local function abbreviate(value: number, decimals: number?): string
	local d = decimals or 1
	local sign = if value < 0 then "-" else ""
	local n = math.abs(value)
	local i = 1
	while n >= 1000 and i < #SUFFIXES do
		n /= 1000
		i += 1
	end
	if i == 1 then
		return sign .. math.floor(n)
	end
	local text = string.format("%." .. d .. "f", n)
	if tonumber(text) >= 1000 and i < #SUFFIXES then
		n /= 1000
		i += 1
		text = string.format("%." .. d .. "f", n)
	end
	if d > 0 then
		text = (text:gsub("%.?0+$", ""))
	end
	return sign .. text .. SUFFIXES[i]
end

print(abbreviate(1500)) --> 1.5K
print(abbreviate(2500000)) --> 2.5M
How it works

Suffixes

SuffixValueExample
Kthousand (10³)12,500 → 12.5K
Mmillion (10⁶)3,400,000 → 3.4M
Bbillion (10⁹)1,000,000,000 → 1B
Ttrillion (10¹²)7.2T
Qaquadrillion (10¹⁵)5Qa
Qiquintillion (10¹⁸)9.1Qi

Luau numbers are 64-bit floats. Integers stay exact up to 2⁵³ (about 9 quadrillion). Above that, simulator-style numbers lose precision, so store huge values as a mantissa and exponent instead.

Leaderstats and GUIs

Leaderstats show raw values, so a StringValue holding the formatted text is the usual trick when you want "1.5M" on the player list. For TextLabels, format the number every time the value changes.

Questions

How do I abbreviate numbers in Roblox?

Divide by the largest power of 1,000 that fits, round to one or two decimals and add the suffix (K, M, B, T). The function on this page does that, handles negative numbers, and moves 999.95K up to 1M instead of printing 1000K.

Why does my number show as 1e+15?

tostring switches to scientific notation for very large numbers. Format the number yourself, or use string.format("%.0f", n) for the full digits.