I trying to get result of grand total with 2 decimals. If i add 3.56 with 4.28 subtotal show result with decimals but grand total show .00 on decimals.
html code
<form>
<div>Quantity:
<input type="text" class="qty">Unit price:
<input type="text" class="unit">Amount:
<input type='text' class='amount'>
</div>
<div>Quantity:
<input type="text" class="qty">Unit price:
<input type="text" class="unit">Amount:
<input type='text' class='amount'>
</div>Total All:
<input type="text" class="result">
jquery code
$(function () {
$('.unit,.qty').on('change', function () {
var unit = $(this).hasClass('unit') ? $(this).val() : $(this).siblings('.unit').val();
var qty = $(this).hasClass('qty') ? $(this).val() : $(this).siblings('.qty').val();
unit = unit || 0;
qty = qty || 0;
var val = unit >= 1 && qty >= 1 ? parseFloat(unit * qty) : 0;
$(this).siblings('.amount').val(val.toFixed(2));
var total = 0;
var update = false;
$('.amount').each(function () {
val = parseFloat($(this).val()) | 0;
total = val ? (parseFloat(total + val)) : total;
});
$('.result').val(total.toFixed(2));
});
});