Skip to content

Instantly share code, notes, and snippets.

@pigeonfresh
Created October 15, 2019 17:33
Show Gist options
  • Save pigeonfresh/d13702a40a2330397cbdf6f7fd92f594 to your computer and use it in GitHub Desktop.
Save pigeonfresh/d13702a40a2330397cbdf6f7fd92f594 to your computer and use it in GitHub Desktop.
const formatNumber = number => (num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'))
console.info(formatNumber(2665)) // 2,665
console.info(formatNumber(102665)) // 102,665
console.info(formatNumber(111102665)) // 111,102,665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment