Skip to content

Instantly share code, notes, and snippets.

@gnbaron
Created March 22, 2021 21:20
Show Gist options
  • Save gnbaron/a3b371bf6ffc0ce5f4ed0fc9595d6b92 to your computer and use it in GitHub Desktop.
Save gnbaron/a3b371bf6ffc0ce5f4ed0fc9595d6b92 to your computer and use it in GitHub Desktop.
format number with commas in js
export 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