note 41548 added to function.bccomp
| From: | php-general at lists dot php dot net | Date: | Wed, 14 Apr 2004 12:43:50 +0000 |
| Subject: | note 41548 added to function.bccomp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68108@lists.php.net to get a copy of this message | ||
The bccomp function seems to differentiate between negative zero and positive zero. For example:
<?php
echo bccomp('-0.00001', '-0.00000', 2) . "<br>";
echo bccomp('-0.00001', '0.00000', 2) . "<br>";
?>
Outputs the following, which is obviously wrong.
0
-1
As I was only trying to determine if a given value was positive or negative, to a particular number
of decimal places, I came up with the following solution. It is not a general solution though.
function my_bccomp_zero($amount, $scale)
{
if ($amount < 0)
{
return bccomp($amount, '-0.0', $scale);
}
else
{
return bccomp($amount, '0.0', $scale);
}
}
----
Manual Page -- http://www.php.net/manual/en/function.bccomp.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41548
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41548&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41548&report=yes
Search -- http://master.php.net/manage/user-notes.php