Skip to content

Instantly share code, notes, and snippets.

@jaunesarmiento
Last active November 19, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaunesarmiento/5c742b7dcbcb93dda33e to your computer and use it in GitHub Desktop.
Save jaunesarmiento/5c742b7dcbcb93dda33e to your computer and use it in GitHub Desktop.
function toCurrency(f) {
var fs = f.split('.');
var rs = fs[0].split('').reverse().join('');
var i = 0;
var ns = '';
while (i < rs.length) {
ns += (i % 3 == 0) ? ',' + rs[i] : rs[i];
i++;
}
return ns.slice(1).split('').reverse().join('') + '.' + ((fs[1] === undefined) ? '00' : fs[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment