Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Last active January 22, 2023 03:26
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 nocodesupplyco/c4a64fb3882d5145f2121ac13c602620 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/c4a64fb3882d5145f2121ac13c602620 to your computer and use it in GitHub Desktop.
Add Commas to Numbers
// Get the number into a variable
let theNumber = 10000;
// Add commas with regex
let commaNumberRegex = theNumber.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// Alternate approach
let commaNumberFormat = new Intl.NumberFormat().format(num);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment