Re: Bug #51739 tricky string to float conversion
| From: | magic-php at damage dot devloop dot de | Date: | Thu, 01 Sep 2011 08:43:42 +0000 |
| Subject: | Re: Bug #51739 tricky string to float conversion | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314698@lists.php.net to get a copy of this message | ||
Simon J Welsh writes:
On 1/09/2011, at 9:53 AM, magic-php@damage.devloop.de wrote:Ok, then let's discuss the documented behavior ;-) Do you (not the document) really like this behavior? I mean if I am the only one wondering about that behavior it is ok for me. I just want to help PHP. cheers DanielAm Mittwoch, 31. August 2011, 20:48:37 schrieb Shawn McKenzie:The manual clearly states this is how a string is converted into a number: http://php.net/manual/en/language.types.string.php#language.types.string.conversion "The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits." If you don't want the string turned into a number using the documented method, don't use it as one.On 08/31/2011 09:03 AM, magic-php@damage.devloop.de wrote:If I use a string in PHP I don't want PHP to cut this string. Either it uses this string as it is or it gives me an error/warning/false (what ever...). But silently(!!!) using a small piece of a string is not understandable.var_dump((float)"8315e839da08e2a7afe6dd12ec58245d"); results in float(INF)The cast to float is truncating the invalid characters and since your string contains a float that is INF (8315e839) before the truncation at the "d", then it returns INF. Makes perfect sense.