How can i separate numbers with commas?

instead of 1000, i want it to be 1,000. instead of 1000000, i want 1,000,000. and so on. how can i do this?

Here there was a post about this: here

Method:

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

I recommend this solution, so you can avoid the loop completely:

1 Like