Skip to content

Instantly share code, notes, and snippets.

@zdying
Created November 11, 2016 09:24
Show Gist options
  • Save zdying/e27780ebd769d02ee23e05f2413a0c2e to your computer and use it in GitHub Desktop.
Save zdying/e27780ebd769d02ee23e05f2413a0c2e to your computer and use it in GitHub Desktop.
//http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// or use Nuber.prototype.toLocaleString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment