Skip to content

Instantly share code, notes, and snippets.

@janephilipps
Created February 24, 2018 23:49
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 janephilipps/d1768259dbdca00dfcba6245513686f2 to your computer and use it in GitHub Desktop.
Save janephilipps/d1768259dbdca00dfcba6245513686f2 to your computer and use it in GitHub Desktop.
/* This function takes an integer and returns a
 * string representation with commas for every group of 3 digits.
 * See this StackOverflow post for an explanation:
 * https://goo.gl/gfe1H7
 */
var addCommas = function(number) {
return number.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