To compare float values in PHP, the code is as follows −
Example
<?php $val_1 = 56.5325; $val_2 = 90.899; $val_3 = 0.11; if(abs($val_1 - $val_2) < $val_3) { echo "The values are same"; } else { echo "The values are not same"; } ?>
Output
The values are not same
Three values are defined that are floating point numbers. The absolute values of these numbers are compared and relevant message is displayed on the console.