everything is beautiful php intval test code found problems

WBOY
Release: 2016-07-29 08:38:29
Original
836 people have browsed it

$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教程有兴趣的朋友有所帮助。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!