Home >Backend Development >PHP Tutorial >How to determine whether two floating point numbers are equal in php, php points_PHP tutorial
The example in this article describes how to determine whether two floating point numbers are equal in php. Share it with everyone for your reference. The specific analysis is as follows:
Since it is not entirely correct to directly use == to determine whether floating point numbers are equal, a method is given below. First set a precision. If they are equal within the precision range, they are considered equal, otherwise they are considered invalid
<?php $delta = 0.00001; $a = 1.00000001; $b = 1.00000000; if (abs($a - $b) < $delta) { /* $a and $b are equal */ } ?>
I hope this article will be helpful to everyone’s PHP programming design.