Home >Backend Development >PHP Tutorial >How to determine whether two floating point numbers are equal in php, php points_PHP tutorial

How to determine whether two floating point numbers are equal in php, php points_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:461112browse

How to determine whether two floating point numbers are equal in php, php points

The example in this article describes 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:

Since it is not entirely 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

<&#63;php
$delta = 0.00001;
$a = 1.00000001;
$b = 1.00000000;
if (abs($a - $b) < $delta) { /* $a and $b are equal */ }
&#63;>

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967737.htmlTechArticlephp method to determine whether two floating point numbers are equal, php points This article describes the example of php determining whether two floating point numbers are equal equal method. Share it with everyone for your reference. The specific analysis is as follows:...
Statement:
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