xxxxxxxxxx
var example = 3.35464464374256 ;
example = parseFloat(example.toFixed(2)) ; // example == 3.35
xxxxxxxxxx
var myNumber=12.2345;
var myNumberWithTwoDecimalPlaces=parseFloat(myNumber).toFixed(2); //12.23
xxxxxxxxxx
Number(1).toFixed(2); // 1.00
Number(1.341).toFixed(2); // 1.34
Number(1.345).toFixed(2); // 1.34 NOTE: See andy's comment below.
Number(1.3450001).toFixed(2); // 1.35
xxxxxxxxxx
const number = 42.56789;
const numberWithTwoDecimals = number.toFixed(2);
console.log(numberWithTwoDecimals); // Output: "42.57"
xxxxxxxxxx
const number = 3.14159265359;
const formattedNumber = number.toFixed(2);
console.log(formattedNumber); // Output: 3.14
xxxxxxxxxx
var discount = Math.round((100 - (price / listprice) * 100) * 100) / 100;