Morning,
I am having an issue adding up some totals using jQuery.
I am passing the following in to this…
- Price – 600.00
- Shipping – 4.05
However i am getting the following results…
subTotal = 600
productShipping = 4.05
orderTotal = 4.05600
$.each(result, function (index, res) {
var price = 600.00; //res.productPrice;
var subTotal = res.itemQty * price;
var orderTotal = res.productShipping + subTotal;
new_record = "<tr>" +
"<td class=\"totals\">Sub Total</td>" +
"<td>£" + subTotal + "</td>" +
"</tr>" +
"<tr>" +
"<td class=\"totals\">Shipping</td>" +
"<td>£" + res.productShipping + "</td>" +
"</tr>" +
"<tr>" +
"<td class=\"totals\">Order Total</td>" +
"<td>£" + orderTotal + "</td>" +
"</tr>";
$('#orderTotals').append(new_record);
I have a feeling there might be some issues with my jQuery adding up these items, however i can work it out. Could someone please shed some light on where i am going wrong.
res is the response i am using from the webservice call.
Many Thanks.
+will concatentate strings as well as add together numbers. As you’re getting concatentation, we can assume thatres.productShippingis a string.Therefore parse it to a float before adding up: