Skip to content

Instantly share code, notes, and snippets.

@letsgetrandy
Last active January 19, 2017 19:49
Show Gist options
  • Save letsgetrandy/5577a15fe3e04163b3b0 to your computer and use it in GitHub Desktop.
Save letsgetrandy/5577a15fe3e04163b3b0 to your computer and use it in GitHub Desktop.
Format whole numbers with commas at every 3rd digit.
function fmtWholeNum (num) {
var n = parseFloat(num.toString().replace(/[^\d\.]+/, '')),
s = Math.floor(n).toString();
return s.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment