JS Coding Questions Logo
JS Coding Questions
#289💼 Interview💻 Code

How do you print numbers with commas as thousand separators

Advertisement

728x90

You can use the Number.prototype.toLocaleString() method which returns a string with a language-sensitive representation such as thousand separator, currency etc. of this number.

javascript
1function convertToThousandFormat(x) {
2  return x.toLocaleString(); // 12,345.679
3  }
4
5console.log(convertToThousandFormat(12345.6789));

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 33

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
289of476
How do you print numbers with commas as thousand separators | JSCodingQuestions.com