Home > Backend Development > PHP Tutorial > Problems found in the test code of php intval_PHP tutorial

Problems found in the test code of php intval_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:50:36
Original
821 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 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319364.htmlTechArticle?php $o=0.1; for($a=1;$a100;$a++){ $o+=0.1; echo"br/intval('$o')=".intval($o); if(intval($o)){ print("true"); }else{ print("false"); } } ? 结果: intval('0.2')=0false intval('0.3'...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template