$a = "1.2424"; Direct Assignment
$b = 1.2424; Read from the MySQL database float field
if (floatval ($a) >= $b) {
Echo 1;
}
I know that floating point numbers have precision problems and need to be compared by Bccomp.
However, can the above example be directly compared? If not, please cite examples of failure
A b variable is directly assigned, and no operation is done before and after the assignment, and is directly compared by the algorithm.
Reply content:
$a = "1.2424"; Direct Assignment
$b = 1.2424; Read from the MySQL database float field
if (floatval ($a) >= $b) {
Echo 1;
}
I know that floating point numbers have precision problems and need to be compared by Bccomp.
However, can the above example be directly compared? If not, please cite examples of failure
A b variable is directly assigned, and no operation is done before and after the assignment, and is directly compared by the algorithm.
No.
php -r "var_dump( 1242.4/1000, floatval('1.2424') >= 1242.4/1000 );"float(1.2424)bool(false)