I'm getting weird, very small negative numbers when subtracting what should be the same two numbers, but only sometimes depending on the multiplier.
So, in this example, 9.95 is multiplied by 1 thought 100 and is subtracted by the same number, or in this case 1 times the same number.
Here's some sample code that demonstrates the issue:
for($i = 1; $i < 100; $i++)
{
$discountAmount = 100;
$orderTotal = 9.95 $i;
$discountAmount = $discountAmount/100; //convert to percent:
$discountTotal = $orderTotal $discountAmount;
$discountTotal = $discountTotal + 0.0001;
$discountTotal = round($discountTotal,2);
$orderTotal = $orderTotal - $discountTotal;
echo "<br><b>". $i . ":</b> " . $orderTotal;
}
Here's a link that shows the results:
http://www.northerncoloradorentals.com/test/temp2.php
If I comment out both of these lines of code it works fine:
$discountTotal = $discountTotal + 0.0001;
$discountTotal = round($discountTotal,2);
But if I leave either one in, I have the same problem.
I don't think this is a case of not being able to represent certain floating point numbers...but I'm not entirely certain.
Any ideas would be greatly appreciated. Thanks.