This is one of the most bizarre problems I’ve run into so far,
I have two numbers which I am trying to add up in php but for some reason php does not give me the correct result.
I am trying to add the $itemPrice with the $shipPrice which is 3.50 + 2.80 that should give me 6.30 but instead I get 5.
I have tried using the floatVal() function but that makes no difference, does anyone have any ideas?
below is a sample of the code
php code
foreach($resp->ListOrderItemsResult->OrderItems->OrderItem as $order){
$itemPrice = $order->ItemPrice->Amount;
$shipPrice = $order->ShippingPrice->Amount;
$total = $itemPrice + $shipPrice;
$arr[] = array(
'sku' => $order->SellerSKU,
'isbn' => $order->ASIN,
'title' => $order->Title,
'item_price' => $itemPrice,
'ship_price' => $shipPrice,
'total' => $total,
'quantity_shipped' => $order->QuantityShipped,
);
}
output
sku isbn title item_price ship_price total quantity_shipped
VM-F5TU-BN0K 1844831531 xxxxx 3.50 2.80 5 1
My guess is that $itemPrice and $shipPrice are strings and when you try to add them together you are getting a value of 5. Make sure you are specifically casting the $itemPrice and $shipPrice as floats if there are stored in your object as strings.