Last active
December 19, 2020 03:57
-
-
Save iamravenous/f76c240d453baa63328e to your computer and use it in GitHub Desktop.
A handy and fast way to format numbers as currency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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