note 24913 deleted from language.operators.arithmetic by sniper
| From: | sniper@php.net | Date: | Mon, 13 Oct 2003 00:08:11 +0000 |
| Subject: | note 24913 deleted from language.operators.arithmetic by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58383@lists.php.net to get a copy of this message | ||
Note Submitter: saforres@alumni.SPAMGUARD.uwaterloo.ca
----
niekomaatjes@hotmail.com wrote:
"To avoid this, you can add a real tiny fraction to the total, like this:
(int)($foo / $bar + 0.0000001)"
This sort of strategy will not work. Suppose $foo=9999999 and $bar=10000000. Then since
$foo<$bar, you would want int($foo/$bar) to return 0, but 9999999/10000000+0.0000001=1.000000000,
so (int)($foo / $bar + 0.0000001)=1.
It's not generally a good idea to rely on truncated floats for integer divisions.