<?php
int bccomp ( string $num1,
string $num2,
?int $scale = null )
where,
$num1 = The left operand as STRING
$num2 = The right operand as STRING
$scale = The number of decimal places
to be considered in the comparison
?>
<?php
function compare01($val01a, $val01b, $scl01)
{
if(bccomp($val01a, $val01b, $scl01) == 0)
{
echo $val01a . ' = ' . $val01b .
' [ ' . $scl01 . ' decimal places ]<br><br>';
}
elseif(bccomp($val01a, $val01b, $scl01) == 1)
{
echo $val01a . ' > ' . $val01b .
' [ ' . $scl01 . ' decimal places ]<br><br>';
}
elseif(bccomp($val01a, $val01b, $scl01) == -1)
{
echo $val01a . ' < ' . $val01b .
' [ ' . $scl01 . ' decimal places ]<br><br>';
}
}
compare01('2020', '2020', 3);
compare01('2021', '2020', 0);
compare01('2020', 2021, 0);
compare01(2020.876, 2020.878, 2);
compare01(2020.876, 2020.878, 3);
compare01(2020.878, 2020.878, null);
?>
<?php
function compare02($val02a, $val02b)
{
if(bccomp($val02a, $val02b) == 0)
{
echo $val02a . ' = ' . $val02b . '<br><br>';
}
elseif(bccomp($val02a, $val02b) == 1)
{
echo $val02a . ' > ' . $val02b . '<br><br>';
}
elseif(bccomp($val02a, $val02b) == -1)
{
echo $val02a . ' < ' . $val02b . '<br><br>';
}
}
bcscale(3);
compare02('2020', '2020');
bcscale(0);
compare02('2021', '2020');
compare02('2020', 2021);
bcscale(2);
compare02(2020.876, 2020.878);
bcscale(3);
compare02(2020.876, 2020.878);
?>