
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP program to compare float values
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.
- Related Articles
- Java Program to compare Two Java float Arrays
- PHP program to compare two dates
- How to compare float and double in C++?
- Comparing float value in PHP
- JavaScript subtraction of two float values?
- Compare two float arrays in a single line in Java
- How to convert amount to float and round correctly in PHP?
- How to compare field values in MongoDB?
- Java Program to convert float to String
- PHP program to find standard deviation of values within an array
- Compare define() vs const in PHP
- Java Program to Compare Strings
- If elseif else or ternary operator to compare numbers PHP?
- PHP Returning values
- Java Program to convert Java String to Float Object

Advertisements