Everything is beautiful PHP intval test Code Discovery problem

Source: Internet
Author: User
$o = 0.1;
for ($a = 1; $a < $a + +) {
$o + = 0.1;
echo "
Intval (' $o ') = ". Intval ($o);
if (Intval ($o)) {
Print ("true");
}else{
Print ("false");
}
}
?>
Results:
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
.....
found that intval (1) actually returned 0
Not testing, not knowing.
Illusion:
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

The above describes the everything is beautiful PHP intval test code Discovery problem, including the everything is beautiful content, I hope that the PHP tutorial interested in a friend to help.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.