At 12:39 PM -0500 7/14/08, Jay Blanchard wrote:
Each number represented by a variable in all of these calculations has
been rounded to 2 decimal points at the point they are generated. For
the most part this works just hunky-dory but I have a handful of calcs
(out of 300k plus records) that look like this....

$endingBal              0.10
$totalBalance   0.30
$totalCharges   0.20
$totalChargeDiff        -0.10

The balance minus the charges does equal the ending balance as it should
but it is saying that it doesn't and that there a 20 cent swing (-0.10
is 20 cents different than 0.10).

I must be missing something. When I echo out raw data I do not see
negative signs. Does anyone have any insight as to what might be
happening here?

Sounds like rounding errors.

Please note that the php rounding function (like all rounding functions) is not accurate. You can write one that is more accurate -- like I did -- but, to see any real difference you have to be dealing with millions of calculations.

Round-off errors normally don't enter into things unless your doing multiplication and division operations. At that point, what you get back from the operation is an approximation and not the actual number. The difference between the sums of all the approximations the the sums of all the calculations you do manually IS going to be different. The difference depends upon how accurate the machines' operations are and in what order the calculations are performed, which is probably the reason for the differences you see here using php to do both, but in different order.

My $0.01999999999995

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to