Reputation: 36753
//Value being parsed at this point is "150.00"
var productValue = parseFloat($("#product-cost-value-value").text().replace(',', '.'));
console.log(productValue);
The value being logged is 150
.
However if I add some value to it, like this. The value changes to display the two decimals I want.
console.log(productValue + 0.01);
The value being logged is 150.01
How can I force my values to show two decimal places at all time?
Upvotes: 7
Views: 10100
Reputation: 303361
Use Number.prototype.toFixed(2)
(e.g. productValue.toFixed(2)
) to convert your number into a string formatted to two decimal places.
Upvotes: 3