Skip to content

Instantly share code, notes, and snippets.

@edrisranjbar
Created May 5, 2024 11:20
Show Gist options
  • Save edrisranjbar/b06aa68c3a996a0742153f8fc2e8c5fe to your computer and use it in GitHub Desktop.
Save edrisranjbar/b06aa68c3a996a0742153f8fc2e8c5fe to your computer and use it in GitHub Desktop.
Add commas to currency in JavaScript
const 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