Skip to content

Instantly share code, notes, and snippets.

@DarrylErentzen
Created November 24, 2016 11:44
Show Gist options
  • Save DarrylErentzen/f5ee6c85950719e9485d68029afd1622 to your computer and use it in GitHub Desktop.
Save DarrylErentzen/f5ee6c85950719e9485d68029afd1622 to your computer and use it in GitHub Desktop.
JavaScript function to format number as currency
function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment