Created
October 19, 2015 21:22
-
-
Save juanbrujo/3bca706e876dccf0fb1d to your computer and use it in GitHub Desktop.
transforms a number to currency used in Chile, adds '$''
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
/*! | |
* numberToCurrency(@number) | |
* transforms a number to currency used in Chile, adds '$'' | |
* @number: int | |
* http://stackoverflow.com/a/17563787/2148418 | |
* USE: numberToCurrency(876142) // returns $876.142 | |
*/ | |
function numberToCurrency(number){ | |
return "$" + (number + "").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment