Skip to content

Instantly share code, notes, and snippets.

@andrewlaskey
Created August 9, 2013 22:00
Show Gist options
  • Save andrewlaskey/6197651 to your computer and use it in GitHub Desktop.
Save andrewlaskey/6197651 to your computer and use it in GitHub Desktop.
Print a number in javascript with commas as thousands separators
//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, ",");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment