Categories
JavaScript Answers

How to add space between numbers with JavaScript?

Spread the love

Sometimes, we want to add space between numbers with JavaScript.

In this article, we’ll look at how to add space between numbers with JavaScript.

How to add space between numbers with JavaScript?

To add space between numbers with JavaScript, we use the number toLocaleString method.

For instance, we write

const num = 1234567890;
const result = num.toLocaleString("fr");

to call num.toLocaleString with "fr" to return a number in the Frenchlocale.

This will return '1 234 567 890'.

Conclusion

To add space between numbers with JavaScript, we use the number 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 *