Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
communitycreator

How to print a number with commas as thousand's separators in JS

Gutha Vamsi Krishna

Overview

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().

Syntax

(num).toLocaleString()

Parameter

  • en-US: This accepts locale as a parameter. We will pass en-US as a locale parameter.

Return value

  • This method returns a number with commas as thousands separated.

Example

Let's take a look at an example code:

console.log((2982932323).toLocaleString('en-US'))
Separating a number with commas using toLocalString().

Explanation

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

javascript
communitycreator
RELATED COURSES

View all Courses

Keep Exploring