How to sort a number with ,

so basically whenever the player has some money, over 1000, I want that 1000 to be sorted as 1,000

the same for 1000000, I need it to be 1,000,000

how do I sort something like this

1 Like
local Numbers = {"1,000", "500", "2,000", "3,000,000"}
table.sort(Numbers, function(Left, Right)
	Left, Right = string.gsub(Left, ",", ""), string.gsub(Right, ",", "")
	Left, Right = tonumber(Left), tonumber(Right)
	return Left > Right
end)
for _, Number in ipairs(Numbers) do
	print(Number)
end
--3,000,000
--2,000
--1,000
--500
1 Like