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

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

WBOY
Release: 2016-06-13 10:16:27
Original
897 people have browsed it

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> 
Copy after login
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>
Copy after login
PHP code
boolean trueboolean false$var['peilv']:55.3$tempCurPeilv:55.3boolean false<br><font color="#e78608">------解决方案--------------------</font><br>因为你的比较变成了字符串和浮点数或者其他类型的比较所以结果就出现了你说的异常。<div class="clear">
                 
              
              
        
            </div>
Copy after login
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