Home  >  Article  >  Backend Development  >  字符串相等缘故

字符串相等缘故

WBOY
WBOYOriginal
2016-06-13 11:48:51906browse

字符串相等原因
请教一下,为何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 />

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