You can try with this. You have this error because we can not divide by 'zero' (0)
value. So we want to validate before when we do calculations.
if ($itemCost != 0 && $itemCost != NULL && $itemQty != 0 && $itemQty != NULL)
{
$diffPricePercent = (($actual * 100) / $itemCost) / $itemQty;
}
And also we can validate POST
data. Refer following
$itemQty = isset($_POST['num1']) ? $_POST['num1'] : 0;
$itemCost = isset($_POST['num2']) ? $_POST['num2'] : 0;
$itemSale = isset($_POST['num3']) ? $_POST['num3'] : 0;
$shipMat = isset($_POST['num4']) ? $_POST['num4'] : 0;