Re: String -> Number Automatic Conversion

From: Date: Thu, 03 Feb 2005 16:41:40 +0000
Subject: Re: String -> Number Automatic Conversion
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-207999@lists.php.net to get a copy of this message
Nuzzo Art-CINT116 wrote: > 1 => "-.15" + 0, > 6 => "-1.15" + 0, > [1] => 0 > [6] => -1.15 > Is this a bug or am I missing something. Looks like a bug to me... It's remotely possible that it's documented somewhere that "-.15" doesn't turn into a number, but that would be pretty bogus, eh? But who knows: There may well be a technical or philosophical reason for not allowing that format. I can't see why, but I ain't the guy writing the code :-) Check and file it at http://bugs.php.net I suppose it's also remotely possible that "rounding errors" are at fault, but that's pretty damn big round error... More likely, the regex to detect a "number" at the start of a string doesn't include "-.[0-9]*" as a valid case. Possible work-around: I suspect that $p1[14] = "-0.15" + 0; will do what you want, since the leading 0 will probably trigger the regex properly. Try it and see. PS You should probably have posted the PHP version and whatnot as well, as I wouldn't be surprised if the bug is version-specific... -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#207999) next »