0

I want to display the 00 after the decimal points but when i try to use the following: console.log(Number("5000.00").toLocaleString('en')); or console.log(parseFloat("5000.00").toLocaleString('en'));

the output which i get in both cases is 5,000 and if i use the following : console.log(Number("5000.02").toLocaleString('en')); or console.log(parseFloat("5000.02").toLocaleString('en')); the output which i get in both above cases is 5,000.02

I want to get 5,000.00 as output in the first 2 cases i.e when the value is "5000.00". How can i achieve this?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

2 Answers2

0

If you want to always show or round off to 2 decimal places you can use toFixed().

Number("5000.00").toFixed(2).toLocaleString('en);
imran shoukat
  • 1,059
  • 2
  • 8
  • 16
0

Shameless reference to a smarter user than me. JavaScript Number.toLocaleString() with 4 digits after separator

console.log(Number("5000.00").toLocaleString("en", { minimumFractionDigits: 2 }))
Matt
  • 171
  • 1
  • 2