Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript value doesn't display decimals unless it's something 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 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?

like image 635
Only Bolivian Here Avatar asked Nov 08 '11 13:11

Only Bolivian Here


1 Answers

use:

console.log(productValue.toFixed(2));
like image 80
Variant Avatar answered Sep 28 '22 01:09

Variant