Created
October 28, 2014 10:02
-
-
Save JaysonChiang/69011e7a64767c0aad5f to your computer and use it in GitHub Desktop.
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 thousandComma(number) { | |
var num = number.toString(); | |
var pattern = /(-?\d+)(\d{3})/; | |
while (pattern.test(num)) { | |
num = num.replace(pattern, "$1,$2"); | |
} | |
return num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment