I already saw the problem of floating comparisons with integers and decimals. Here is explained in the red box: link
To solve this we have the library: BCMath arbitrary precision math : link
And supposedly the function would come from luxury: int bccomp (string $ left_operand, string $ right_operand [ int $ scale = 0])
Well ... It Does not Work !!!! I have developed an ecommercer that until now the discounts were percents of whole numbers.
Now the discounts can be: - Entire percentages - Percentages with decimals - Amount with decimals
And at the time of seeing in a matrix if there is a discount comes the problem. Try this code:
var_dump(0.61);
var_dump(0.00);
var_dump(bccomp(0.61, 0));
It is assumed that 0.61 is greater than 0
Well, the function returns this:
float (0.61) float (0) int (0)
PHP 7.1.22 tells me that 61 cents and nothing is the same.
What am I doing wrong? In my code everything is varied and in the comparisons I always force the values:
if (bccomp((real)$matrizpvp[2], 0.00) !== 0)
if (bccomp((real)$matrizpvp[2], 0) !== 0)
I have tried both ways, even putting the zero in a variable.