-
-
Save nocodesupplyco/c4a64fb3882d5145f2121ac13c602620 to your computer and use it in GitHub Desktop.
Add Commas to Numbers
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
// Get the number into a variable | |
let theNumber = 10000; | |
// Add commas with regex | |
let commaNumberRegex = theNumber.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
// Alternate approach | |
let commaNumberFormat = new Intl.NumberFormat().format(num); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment