A Javascript value does not display decimals, unless anything other than 0.00

//Value being parsed at this point is "150.00" var productValue = parseFloat($("#product-cost-value-value").text().replace(',', '.')); console.log(productValue); 

The recorded value is 150 .

However, if I add some value to it, for example. The value will change to display the two decimal places I want.

 console.log(productValue + 0.01); 

Recorded Value: 150.01

How can I make my values ​​show two decimal places at once?

+4
source share
3 answers

using:

 console.log(productValue.toFixed(2)); 
+9
source

Use productValue.toFixed(2) to display 2 decimal places

+3
source

Use Number.prototype.toFixed(2) (e.g. productValue.toFixed(2) ) to convert your number to a string formatted to two decimal places.

+2
source

Source: https://habr.com/ru/post/1380191/


All Articles