So I have this code:

function addCommas(str)
	return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
end

But, that's way to complex for me. I need a way to more simply insert commas into numbers above 999.

5 comments

0

it works just fine dude idk what you're talking about this

0

literally just call the function using addComas(number)

0

Could get the length then scan through the original number, adding a comma in the desired position

0

wait, so you're saying i could just get the length of the number, then add a comma in every 3rd number?

0

yes