intval('$o') = ".intval($o); if(intval($o)){ print(" true"); }else{ pr"/> intval('$o') = ".intval($o); if(intval($o)){ print(" true"); }else{ pr">

Home  >  Article  >  Backend Development  >  everything is beautiful php intval test code found problems

everything is beautiful php intval test code found problems

WBOY
WBOYOriginal
2016-07-29 08:38:29828browse

$o = 0.1;
for($a = 1; $a < 100; $a++){
    $o += 0.1;
    echo "intval('$o') = ".intval($o);
    if(intval($o)){
        print(" true");
    }else{
        print(" false");
    }
}
?> 
结果:
intval('0.2') = 0 false
intval('0.3') = 0 false
intval('0.4') = 0 false
intval('0.5') = 0 false
intval('0.6') = 0 false
intval('0.7') = 0 false
intval('0.8') = 0 false
intval('0.9') = 0 false
intval('1') = 0 false
intval('1.1') = 1 true
intval('1.2') = 1 true
intval('1.3') = 1 true
intval('1.4') = 1 true
intval('1.5') = 1 true
intval('1.6') = 1 true
intval('1.7') = 1 true
intval('1.8') = 1 true
intval('1.9') = 1 true
intval('2') = 2 true
intval('2.1') = 2 true
intval('2.2') = 2 true
intval('2.3') = 2 true
intval('2.4') = 2 true
intval('2.5') = 2 true
intval('2.6') = 2 true
intval('2.7') = 2 true
intval('2.8') = 2 true
..... 
发现 intval(1) 竟然返回 0 
不测试不会知道的
假象:
print("intval("1.0") = ".intval("1.0"));
print("intval('1.0') = ".intval('1.0'));
print("intval('1') = ".intval('1')); 
intval("1.0") = 1
intval('1.0') = 1
intval('1') = 1 

以上就介绍了everything is beautiful php intval的测试代码发现问题,包括了everything is beautiful方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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