Skip to content

Instantly share code, notes, and snippets.

@electerious
Created September 30, 2016 10:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electerious/85a6ca59b20d936ac7f71d4de36a4cd3 to your computer and use it in GitHub Desktop.
Save electerious/85a6ca59b20d936ac7f71d4de36a4cd3 to your computer and use it in GitHub Desktop.
Format a number
const formatNumber = (num, delimiter = ',') => num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, delimiter)
@electerious
Copy link
Author

Example:

formatNumber(1234567) // '1,234,567'
formatNumber(1234567, '.') // '1.234.567'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment