View Full Version : Why does 08 * 1.5 evaluate to 0?

09-15-2011, 01:43 AM
Simple question. I was taking a test today and wasn't sure about one of the questions, so I started working on it now.

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.

09-15-2011, 02:03 AM
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