Format Number --add comma to seperate thousands

Example usage: amount = 1333444.1 print(format_num(amount,2)) print(format_num(amount,-2,"US$")) amount = -22333444.5634 print(format_num(amount,2,"$")) print(format_num(amount,2,"$","()")) print(format_num(amount,3,"$","NEG "))
Send Snippet To: Save this snippet to Code Collector Pro -- view all roger's snippets
language: Other
license: Other

Code for Snippet:

-- add comma to separate thousands
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
  return formatted
comments powered by Disqus


Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 7
Date Added: 2018-01-09 04:45:35
Last Modified: 2018-01-10 09:54:13

Web Analytics