I have a script that calculates totals based on price, quantity, tax and shipping cost. When I attempt to add them together I receiving high numbers for total cost
Here is the script:
function calculate() {
var total = 0;
var shiptotal = 0;
var subtotal = 0;
var taxtotal = 0;
var taxrate = .078;
$('.button-click').each(function () {
var amt = parseInt($(this).prev().val());
var qty = parseInt($(this).parent().find(".quantity").val());
var ship = parseInt($(this).parent().find(".ik-ship").val());
shiptotal += (ship * qty);
subtotal += (amt * qty);
taxtotal += ( (amt * qty) * taxrate);
total += ( subtotal + shiptotal + taxtotal );
});
$('#Amount').val(total.toFixed(2));
$('.total-amount').html( total.toFixed(2) );
$('.sub-total-amount').html( subtotal.toFixed(2) );
$('.shipping-amount').html( shiptotal.toFixed(2) );
$('.tax-amount').html( taxtotal.toFixed(2) );
}
A product that cost $62.00 and has $3.00 in shipping comes out like this:
SUB-TOTAL: 62.00
SHIPPING: 3.00
TAX: 4.84
TOTAL: 1257.05 <-- incorrect total -->
I may have been in front of the computer for too long but how do I solve this problem? Please provide an example.