Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    186
    Thanks
    72
    Thanked 2 Times in 2 Posts

    Why does 08 * 1.5 evaluate to 0?

    Simple question. I was taking a test today and wasn't sure about one of the questions, so I started working on it now.

    Code:
    echo 08 * 1.5;
    This outputs 0. Why?

    I noticed that when you change 08 to just 8, it returns 12, which is the number that I'd expect. Why does the 0 before the 8 change this evaluation? I would think that the 0 to the left of the 8 would make no difference whatsoever in a decimal based counting system.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    When you write 08 with a leading zero PHP interprets it as an octal number not a decimal number so it is base 8. And there is no 8 in octal so it must be just defaulting to 0. See: http://us3.php.net/manual/en/language.types.integer.php
    OracleGuy

  • Users who have thanked oracleguy for this post:

    skcin7 (09-21-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •