
- 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
Comparing float value in PHP
To compare float values in PHP, the code is as follows −
Example
<?php $a = 2.5; $b = 3.5; echo $a; echo "
$b"; if($a == $b) { echo "
Both the values are equal!"; } else { echo "
Both the values aren\'t equal"; } ?>
Output
This will produce the following output−
2.5 3.5 Both the values aren\'t equal
Example
Let us now see another example −
<?php $a = 1.967; $b = 1.969; echo $a; echo "
$b"; if((round($a, 2)) == (round($b, 2))) { echo "
Both the values are equal!"; } else { echo "
Both the values aren\'t equal"; } ?>
Output
This will produce the following example−
1.967 1.969 Both the values are equal!
- Related Articles
- PHP Comparing Objects
- Comparing two dates in PHP
- PHP program to compare float values
- Convert tuple to float value in Python
- Grouping array nested value while comparing 2 objects - JavaScript
- How to convert amount to float and round correctly in PHP?
- What is the maximum value of float in Python?
- Calculate the absolute value of float values in Numpy
- Split float value in two columns of a MySQL table?
- Comparing dates in Python
- Get the angle whose sine is float value argument in C#
- Sort php multidimensional array by sub-value in PHP
- Comparing Enumeration Values in Java
- Comparing two strings in MySQL?
- Comparing enum members in C#

Advertisements