Skip to content

Instantly share code, notes, and snippets.

@JaysonChiang
Created October 28, 2014 10:02
Show Gist options
  • Save JaysonChiang/69011e7a64767c0aad5f to your computer and use it in GitHub Desktop.
Save JaysonChiang/69011e7a64767c0aad5f to your computer and use it in GitHub Desktop.
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