I want to compare two floats in PHP, like in this sample code:
$a = 0.17;
$b = 1 - 0.83; //0.17
if($a == $b ){
echo \'a and b are same\';
}
else {
echo \'a
Read the red warning in the manual first. You must never compare floats for equality. You should use the epsilon technique.
For example:
if (abs($a-$b) < PHP_FLOAT_EPSILON) { … }
where PHP_FLOAT_EPSILON
is constant representing a very small number (you have to define it in old versions of PHP before 7.2)