PHP program to compare float values


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.

Updated on: 02-Jul-2020

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements