RE: Ranges for case statement and a WTF moment.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: David Harkness [mailto:david.h@xxxxxxxxxxxxxxxxx]
> Sent: 06 April 2011 21:08
> To: Richard Quadling; PHP General list
> Subject: Re:  Ranges for case statement and a WTF moment.
> 
> On Tue, Apr 5, 2011 at 8:28 AM, Richard Quadling
> <rquadling@xxxxxxxxx>wrote:
> 
[...]
> > 10...19
> >
> > What I'm not sure is why the middle empty string is output as 0.
> >
> > "10" . . ".19" becomes "10" . "0" . ".19" which becomes "100.19"
> >
> 
> My guess is that PHP parses this as
> 
>     10<decimal-point> <dot-operator> <decimal-point>19
> 
> Because the dot operator requires strings, PHP converts both numbers
> to
> strings as
> 
>     '10' <dot-operator> '0.19'
> 
> which becomes your
> 
>     100.19
> 
> You can see this with
> 
>     php > echo (string) 10.
>     10
>     php > echo (string) .19
>     0.19

Oh, excellent deduction! I must admit, my first instinct was also that
both numbers should absorb a dot if one of them did, but failed to
realise that .19 would be coerced to "0.19". Just shows how you really
have to think things through, sometimes!

Cheers!

Mike

 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507 City Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.ford@xxxxxxxxxxxxxx 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux