Home > Backend Development > PHP Tutorial > php判断两个浮点数是否相等的方法_php技巧

php判断两个浮点数是否相等的方法_php技巧

WBOY
Release: 2016-05-16 20:20:52
Original
1492 people have browsed it

本文实例讲述了php判断两个浮点数是否相等的方法。分享给大家供大家参考。具体分析如下:

由于浮点数直接用==判断是否相等是不完全正确的,所以下面给出了一个方法,先设定的一个精度,如果在精度范围内相等则认为相等,否则认为不能

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

希望本文所述对大家的php程序设计有所帮助。

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