Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tobidsn
Forked from fjaguero/numberWithThousands.js
Created July 12, 2019 10:50
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 tobidsn/e07e59de6fc4d19043167c83d949f6d8 to your computer and use it in GitHub Desktop.
Save tobidsn/e07e59de6fc4d19043167c83d949f6d8 to your computer and use it in GitHub Desktop.
JS Regex: Adds thousands separator to a number.
// Adds the thousands separator
function numberWithThousands(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