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);
}
}