[PHP] Dumb Question - Casting

2010-02-18 Thread Chuck
Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates to 7 and not 8? $a = (int) (0.1 +0.7); echo $a\n; $x = (int) ((0.1 + 0.7) * 10); echo $x\n; $y = (int) (8); echo $y\n;

Re: [PHP] Dumb Question - Casting

2010-02-18 Thread Ashley Sheridan
On Thu, 2010-02-18 at 09:47 -0600, Chuck wrote: Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates to 7 and not 8? $a = (int) (0.1 +0.7); echo $a\n; $x = (int) ((0.1 + 0.7)

Re: [PHP] Dumb Question - Casting

2010-02-18 Thread Andrew Ballard
On Thu, Feb 18, 2010 at 10:50 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Thu, 2010-02-18 at 09:47 -0600, Chuck wrote: Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates

Re: [PHP] Dumb Question - Casting

2010-02-18 Thread Daniel Egeberg
On Thu, Feb 18, 2010 at 16:47, Chuck chuck.car...@gmail.com wrote: Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates to 7 and not 8? $a = (int) (0.1 +0.7); echo $a\n; $x =

Re: [PHP] Dumb Question - Casting

2010-02-18 Thread Joseph Thayne
According to the PHP manual using the same expression, Never cast an unknown fraction to integer, as this can sometimes lead to unexpected results. My guess is that since it is an expression of floating points, that the result is not quite 8 (for whatever reason). Therefore, it is rounded

Re: [PHP] Dumb Question - Casting

2010-02-18 Thread Nathan Rixham
Daniel Egeberg wrote: On Thu, Feb 18, 2010 at 16:47, Chuck chuck.car...@gmail.com wrote: Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates to 7 and not 8? $a = (int) (0.1 +0.7);