Created
August 9, 2013 22:00
-
-
Save andrewlaskey/6197651 to your computer and use it in GitHub Desktop.
Print a number in javascript with commas as thousands separators
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
//http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript | |
function numberWithCommas(x) { | |
return x.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