PHP Suggested to use these function for floating point number comparison [here]
bccomp — Compare two arbitrary precision numbers
int bccomp ( string $left_operand , string $right_operand [, int $scale ] )
gmp_cmp — Compare numbers
int gmp_cmp ( resource $a , resource $b )
I used bccomp but I cant still get correct result:
<?php
$n1 = bcdiv(1, 2.36, 4);
$n2 = bcdiv(4237288, 10000000, 4);
echo bccomp( $n1, $n2, 4); // 0! must be 1
echo "<br>\n";
var_dump(bcdiv(1, 2.36, 4)); // string(6) "0.4237"
echo "<br>\n";
var_dump(bcdiv(4237288, 10000000, 4)); // string(6) "0.4237"
?>
So far, I knew that the result of 1/2.36 is equal to (0.4237288135593220338983050847457627118644067796610169491525423728813559322033898305084745762711864406......)
Then, how to I know that the number of decimals is great like this?
The possible solution:
$n1 = bcdiv(1, 2.36, 400);
$n2 = bcdiv(4237288, 10000000, 400);
echo bccomp( $n1, $n2, 400); //1
I think this solution is till not more usable.
Any suggestion?