Home > Backend Development > PHP Tutorial > 字符串相等缘故

字符串相等缘故

WBOY
Release: 2016-06-13 11:48:51
Original
945 people have browsed it

字符串相等原因
请教一下,为何PHP认为一下两个字符串是相等的?
if("03E-004611"=="36E-008026") echo '相等';
------解决方案--------------------

本帖最后由 xuzuning 于 2014-02-08 17:10:29 编辑
var_dump("03E-004611"=="36E-008026"); //bool(true)<br />var_dump(03E-004611, 36E-008026); //float(0) float(0)<br />var_dump("03E-004611"==="36E-008026"); //bool(false)<br />
Copy after login

由数字组成的串,在比较时会先转换为数值
------解决方案--------------------
因为E是10的幕运算 "03E-004611"转换成符点数时已经无限接近0了,3*pow(10,-4611),达不到这么高的精度,所以就都是0了.
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