Skip to content

Instantly share code, notes, and snippets.

@coffeepostal
Created February 17, 2017 23:19
Show Gist options
  • Select an option

  • Save coffeepostal/6046a8b46439b4fb7509adef56f9b44c to your computer and use it in GitHub Desktop.

Select an option

Save coffeepostal/6046a8b46439b4fb7509adef56f9b44c to your computer and use it in GitHub Desktop.
jQuery: Add Commas to Thousands
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return val;
}
$('#inputID').val(commaSeparateNumber(1234567890));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment