I’ve got a function that divides a number (in this case, 2500), by 24. In this case, it is 104.166666 repeating, and when I calculate it to 2 places, i get 104.17 (which is correct). However, how can I make it round to 104.16 instead (rounding down)?
var sum = parseFloat(val1) * parseFloat(val2); //here sum is = to 104.1666666
if (isNaN(sum)) {
sum = 0;
}
total.val(parseFloat(sum).toFixed(2)); // here it becomes 104.17, but I want it to round down instead
Try doing this, by multiplying by 100, you get your desired precision, floor that down, and divide by 100 to put the decimal places back where they belong 🙂