Skip to content

Instantly share code, notes, and snippets.

@iamravenous
Last active December 19, 2020 03:57
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 iamravenous/f76c240d453baa63328e to your computer and use it in GitHub Desktop.
Save iamravenous/f76c240d453baa63328e to your computer and use it in GitHub Desktop.
A handy and fast way to format numbers as currency
/*
* Format Numbers
* A handy and fast way to format numbers as currency
* Author: Franco Moya - @iamravenous
* Version: 0.1.1
*/
function formatNumbers(value) {
var a = value.toString();
var b = '';
var $separator = '.';
while(a.length > 3) {
b = $separator + a.substr(a.length - 3) + b;
a = a.substring(0, a.length - 3);
}
return a + b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment