PHP program to compare float values

PHPServer Side ProgrammingProgramming

To compare float values in PHP, the code is as follows −

Example

 Live Demo

<?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.

raja
Published on 02-Jul-2020 06:44:00
Advertisements