xxxxxxxxxx
function roundDown(amount, decimal){
decimal = +decimal;
const value = +( 1 + (new Array(decimal + 1).join('0')).slice(-decimal));
return Math.floor(+amount * value) / value;
}
xxxxxxxxxx
var subTotal="12.1345";// can also be int, float, string
var subTotalFormatted=parseFloat(subTotal).toFixed(2); //"12.13"
xxxxxxxxxx
Math.round(3.14159) // 3
Math.round(3.5) // 4
Math.floor(3.8) // 3
Math.ceil(3.2) // 4
xxxxxxxxxx
>>> parseFloat(0.9999999.toFixed(4));
1
>>> parseFloat(0.0009999999.toFixed(4));
0.001
>>> parseFloat(0.0000009999999.toFixed(4));
0
xxxxxxxxxx
const number = 3.14159;
const roundedNumber = Math.round(number * 100) / 100;
console.log(roundedNumber);