Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-15-2011, 12:43 AM   PM User | #1
skcin7
Regular Coder

 
Join Date: Jul 2009
Posts: 186
Thanks: 72
Thanked 2 Times in 2 Posts
skcin7 is an unknown quantity at this point
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.
__________________
My website: http://www.nicholas-morgan.com/
skcin7 is offline   Reply With Quote
Old 09-15-2011, 01:03 AM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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
oracleguy is offline   Reply With Quote
Users who have thanked oracleguy for this post:
skcin7 (09-21-2011)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:30 AM.


Advertisement
Log in to turn off these ads.