Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Created October 19, 2015 21:22
Show Gist options
  • Save juanbrujo/3bca706e876dccf0fb1d to your computer and use it in GitHub Desktop.
Save juanbrujo/3bca706e876dccf0fb1d to your computer and use it in GitHub Desktop.
transforms a number to currency used in Chile, adds '$''
/*!
* 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