Home  >  Article  >  Backend Development  >  php是不是有小数部分为.3是不是有漏洞解决方案

php是不是有小数部分为.3是不是有漏洞解决方案

WBOY
WBOYOriginal
2016-06-13 10:16:27832browse

php是不是有小数部分为.3是不是有漏洞
从html页面获取一个值,数据库读一个值,判断如果他们不相等就干某些事情(!=)当两个数字的小数部分是.3时 居然判断错误;
比如两个数都是54.3或55.3它居然判断 true 应该是false,小数部分为其他时没有问题,比如54.2
有碰到过的没

------解决方案--------------------
没问题啊。。。楼主你的代码有问题或者大脑短路了吧。

PHP code
var_dump(54.3 != 55.3);//bool(true)<br><font color="#e78608">------解决方案--------------------</font><br>多次测试,没有发现所说的问题<br><font color="#e78608">------解决方案--------------------</font><br> 
PHP code
<?php $var['peilv'] = 12.345;$tempCurPeilv = 234.54;var_dump($var['peilv'] != $tempCurPeilv);$var['peilv'] = 55.3;$tempCurPeilv = 55.3;var_dump($var['peilv'] != $tempCurPeilv);echo "<br/>";echo '$var[\'peilv\']:',$var['peilv'],'$tempCurPeilv:',$tempCurPeilv;var_dump($var['peilv'] != $tempCurPeilv);<br><font color="#e78608">------解决方案--------------------</font><br>愚人节吗哈哈<br>
PHP code
boolean trueboolean false$var['peilv']:55.3$tempCurPeilv:55.3boolean false<br><font color="#e78608">------解决方案--------------------</font><br>因为你的比较变成了字符串和浮点数或者其他类型的比较所以结果就出现了你说的异常。<div class="clear">
                 
              
              
        
            </div>
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