Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joshuacharleslake/14e5c2dd879433b5b35b2b99c9c6615d to your computer and use it in GitHub Desktop.
Save joshuacharleslake/14e5c2dd879433b5b35b2b99c9c6615d to your computer and use it in GitHub Desktop.
Format a number into currency.
//format number to currency
function formatCurrency(num) {
var p = num.toFixed(2).split(".");
return "£" + p[0].split("").reverse().reduce(function(acc, num, i, orig) {
return num=="-" ? acc : num + (i && !(i % 3) ? "," : "") + acc;
}, "") + "." + p[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment