This shot will teach us how to print a number with commas as a thousand's separators using JavaScript.
We can achieve this by using the method toLocaleString()
.
(num).toLocaleString()
en-US
: This accepts locale
as a parameter. We will pass en-US
as a locale parameter.Let's take a look at an example code:
console.log((2982932323).toLocaleString('en-US'))
In the above code, we call the toLocaleString()
method to print out the number 2982932323
commas as thousand's separators, and passing the en-US
as a locale parameter.
RELATED TAGS
CONTRIBUTOR
View all Courses