In Javascript 2 decimals and comma-separtor in numbers

I want to have 2 decimals and comma-separator in numbers in such a way that decimal comes after comma always.

I have tried this example:

const number = 50000;

console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 2 })
  .format(number));

I also need 2 decimals in this number value.

  • Input: 50000
  • Actual Output: 50,000
  • Expected Output: 50,000.00

Above output is needed in my case.

>Solution :

Here is the solution :

const options = {
                minimumFractionDigits: 2,
                maximumFractionDigits: 2,
              };
let num =  Number(50000).toLocaleString("en", options);
console.log(num);

Leave a Reply