Comparison of floating point numbers

Time:2020-11-23

Floating point size comparison

var_dump(2.7 == 2.7);        //bool(true)

var_dump(8.1/3);    //2.7
#Because of the accuracy, this comparison is not equal to
var_dump(8.1/3 == 2.7); //bool(false)

#This comparison is equal
var_dump(round(8.1/3) == round(2.7)); //bool(true)

Note: when the result of the integer operation is beyond the range of floating-point number

The maximum integer value is: PHP_ INT_ MAX

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint


June wind