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 CodingAdvertisement
728x90
289of476