-1

How can I make a flaoting point number always have two decimal places, even when one is a zero?

E.g var postageCost = 3.2 but I want to display it as 3.20 - is this something that must be added as a string or is it possible to actually change the number?

Francesca
  • 26,842
  • 28
  • 90
  • 153

1 Answers1

0

From Here, you can use

parseFloat(Math.round(postageCost * 100) / 100).toFixed(2);
Community
  • 1
  • 1
Bijan
  • 7,737
  • 18
  • 89
  • 149