I have the following problem: when calculating the cost for delivery of an order, I noticed that in some cases (-1.4210854715202E-14
in my case) a floating point error shows up. You can find the function I am using below, the error shows up when $orderTotal
has the same value as $totalPackagePrice
.
public function getPaidPackages()
{
$orderTotal = doubleval($this->total_price); //price the customer paid for
$totalPackagePrice = doubleval($this->getTotalOrderPrice()); //price of all the orderitems within all the packages combined
//error shows up when substracting the same values (e.g. 68.55 in my case)
$packagingCosts = $orderTotal - $totalPackagePrice; //shows a negative value when debugging
...
}
Any help to tackle this problem is appreciated, so far I've tried to cast both input values to a float
or a double
to no avail.