Format Number -- rounds a number to the nearest decimal places

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:

-- rounds a number to the nearest decimal places
function round(val, decimal)
  if (decimal) then
    return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
    return math.floor(val+0.5)
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: 8
Date Added: 2018-01-09 04:47:22
Last Modified: 2018-01-10 09:54:13

Web Analytics