I am new to Forms, and a Purchase Order request form is my first one. The example code I found on the LF support site works great:
$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
$('.tax').on('blur', 'input', sumtotal);
$('.shipping').on('blur', 'input', sumtotal);
function sumtotal() {
var sum = 0;
$('.cf-table-block tbody tr').each(function () {
var s = 0;
s = parseNumber($(this).find('.price input').val()) * parseNumber($(this).find('.quantity input').val());
$(this).find('.subtotal input').val(s);
sum += s;
sum += parseNumber($('.tax input').val()) + parseNumber($('.shipping input').val());
});
$('.total input').val(sum);
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});
The problem I am having here is that some combinations of quantity/price will result in the extended price (subtotal) going out way past 2 decimal places (example.....14 items @ $14.63 results in a subtotal of $204.82000000000002).
This throws the total after tax and shipping into an "Invalid input."
How can I force the subtotal and total amounts to always be rounded to 2 decimal places?
Thank You