Created
February 17, 2017 23:19
-
-
Save coffeepostal/6046a8b46439b4fb7509adef56f9b44c to your computer and use it in GitHub Desktop.
jQuery: Add Commas to Thousands
This file contains hidden or 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 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