[EMAIL PROTECTED] wrote:
hah yeah, always worth a little skepticism, but it seemed to make some kind of
sense. If you always round up or always round down, that's obviously not
right and you end up losing potentially a lot of money or over-estimating the
money involved.
Founding up for 5 through 9 and down for 0 through 4 seems like it makes some
kind of sense, but apparently it doesn't work out that way.
I'm sure someone out there knows what I'm talking about (it might be the first
time, but I know I'm not making this up hah), but rounding 0.75 up to 0.8 and
0.65 down to 0.6 (or vice versa) is supposed to be more accurate or at least
leads to fewer anomalies.
Someone feel like writing a quick script that generates random numbers and does
the rounding based on these two ideas (doing it the 'hard way') and see how
much variation there is after like 10,000 iterations? If I have time later,
I'll do it. Now I'm even more curious.
I wasn't aware of the accounting trick before today, but I believe I can
explain it: If your numbers are statistically random, then the above
solution will lead to an even distribution of rounding up and rounding down.
The reason is simple:
0: No rounding. It's already there. (8.0 doesn't need to be rounded to 8
- it already *is* 8.)
1-4: You round down -> 4 of 9 times you round down.
5-9: You round up -> 5 of 9 times you round up.
So you round up 11.1% more often than you round down. As a result, if
you round up when it's odd, and down when it's even, you eliminate the
11.1% difference in when you'd round up then round down.
That said, if someone were aware of the above rounding trick, it
wouldn't take someone very much effort to come up with things like "fee
structures" or "pricing structures" that could take advantage of that
scheme to force rounding errors to remain permanently in the person's favor.
I certainly hope that PHP continues to use the standard technique, and
not the "accounting trick" above. :-)
jon
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php