Last active
January 19, 2017 19:49
-
-
Save letsgetrandy/5577a15fe3e04163b3b0 to your computer and use it in GitHub Desktop.
Format whole numbers with commas at every 3rd digit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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