note 41548 deleted from function.bccomp by didou
| From: | didou@php.net | Date: | Sat, 27 Jan 2007 16:55:06 +0000 |
| Subject: | note 41548 deleted from function.bccomp by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122270@lists.php.net to get a copy of this message | ||
Note Submitter:
----
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);
}
}