I need help with adding commas to numbers

Heyyo, I’m making a simulator and I need help with adding commas to numbers (To make the gui easier to read) Here’s an example of what I need

local number = NUMBER

-code for adding commas-

TextLabel.Text = numberwithcomma

Like say the number is 1000 how would I make it display as 1,000

1 Like

I wrote this awhile ago, it’s probably slow but it should work:

local function formatNumber(number)
    local numberString = tostring(number)
	local amountOfCommas = math.round(numberString:len() / 3)
	local splitString = numberString:split('')
	for i = numberString:len() - 2, 1, -3 do
		if i ~= 1 then
			table.insert(splitString, i, ',')
	return table.concat(splitString)
1 Like

Thank you for the code, it really helped me! BTW I am streaming this development on twitch… https://twitch.tv/rogamxr Feel free to say heyyo thx for the help again!