Skip to content

Instantly share code, notes, and snippets.

@gracefullight
Last active December 21, 2016 15:46
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 gracefullight/d39f2407c7ce5d8b6dc01e6a6992aebd to your computer and use it in GitHub Desktop.
Save gracefullight/d39f2407c7ce5d8b6dc01e6a6992aebd to your computer and use it in GitHub Desktop.
// function
function comma(num){
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// prototype
Number.prototype.format = function(){
return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment