Home > Backend Development > PHP Tutorial > PHP method to determine whether two floating point numbers are equal_PHP tutorial

PHP method to determine whether two floating point numbers are equal_PHP tutorial

WBOY
Release: 2016-07-13 10:03:08
Original
806 people have browsed it

How PHP determines whether two floating point numbers are equal

This article describes the example of how PHP determines whether two floating point numbers are equal. Share it with everyone for your reference. The specific analysis is as follows:

Since it is not completely correct to directly use == to determine whether floating point numbers are equal, a method is given below. First set a precision. If they are equal within the precision range, they are considered equal, otherwise they are considered invalid

<?php
$delta = 0.00001;
$a = 1.00000001;
$b = 1.00000000;
if (abs($a - $b) < $delta) { /* $a and $b are equal */ }
?>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969341.htmlTechArticleHow to determine whether two floating point numbers are equal in PHP. This article explains how to determine whether two floating point numbers are equal in PHP. . Share it with everyone for your reference. The specific analysis is as follows: Due to floating point...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template