xxxxxxxxxx
var numb = 80.124124124;
numb = numb.toFixed(2);
// numb = 80.12
xxxxxxxxxx
var subTotal="12.1345";// can also be int, float, string
var subTotalFormatted=parseFloat(subTotal).toFixed(2); //"12.13"
xxxxxxxxxx
function roundTo2(num) {
return Math.round( ( num + Number.EPSILON ) * 100 ) / 100;
}
xxxxxxxxxx
>>> parseFloat(0.9999999.toFixed(4));
1
>>> parseFloat(0.0009999999.toFixed(4));
0.001
>>> parseFloat(0.0000009999999.toFixed(4));
0
xxxxxxxxxx
let num = 12.3456; // The number to round
let roundedNum = num.toFixed(2); // Rounding to two decimal places
console.log(roundedNum); // Output: 12.35