

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 "\n$b"; if($a == $b) { echo "\nBoth the values are equal!"; } else { echo "\nBoth 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 "\n$b"; if((round($a, 2)) == (round($b, 2))) { echo "\nBoth the values are equal!"; } else { echo "\nBoth the values aren\'t equal"; } ?>
Output
This will produce the following example−
1.967 1.969 Both the values are equal!
- Related Questions & Answers
- 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
- What is the maximum value of float in Python?
- Calculate the absolute value of float values in Numpy
- Comparing dates in Python
- Jasmine.js comparing arrays
- Split float value in two columns of a MySQL table?
- How to convert amount to float and round correctly in PHP?
- Comparing enum members in Java
- Comparing enum members in C#
- Comparing Enumeration Values in Java
- Comparing two strings in MySQL?
Advertisements