Categories
JavaScript Answers

How to add commas or spaces to group every three digits with JavaScript?

Spread the love

Sometimes, we want to add commas or spaces to group every three digits with JavaScript.

In this article, we’ll look at how to add commas or spaces to group every three digits with JavaScript.

How to add commas or spaces to group every three digits with JavaScript?

To add commas or spaces to group every three digits with JavaScript, we use the toLocaleString method.

For instance, we write

console.log(Number(1234567890.12).toLocaleString());

to call toLocaleString on the number to return a string with the thousands separators included.

Conclusion

To add commas or spaces to group every three digits with JavaScript, we use the toLocaleString method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *