Error Calculating With Decimals
Posted: Thu Apr 22, 2010 10:38 am
I'm running into a very strange issue where very cut and dry math is getting distorted by PHP. Here's the function:
If I give this function a value of 175, it returns 251. It should be 250 (175 / .7 = 250). When I look at it with the debugger, $stockingPrice = 175, $price = 250 but $decimal is 2.8421709430404E-14, which is causing the ceiling function to return 251.
Any ideas why this is happening? It's jacking up our pricing! Thanks!
Code: Select all
private function GetListPrice($stockingPrice)
{
$price = $stockingPrice / .7;
$decimal = $price - floor($price);
if ($price > 100)
return ceil($price);
else
{
if ($decimal <= .5)
return floor($price) + .5;
else
return floor($price) + 1;
}
}
Any ideas why this is happening? It's jacking up our pricing! Thanks!