Bug #51739 [Opn->Bgs]: tricky string to float conversion
Edit report at http://bugs.php.net/bug.php?id=51739&edit=1
ID: 51739
Updated by: aharvey@php.net
Reported by: daniel dot buschke at nextiraone dot de
Summary: tricky string to float conversion
-Status: Open
+Status: Bogus
Type: Bug
Package: *General Issues
PHP Version: 5.2.13
New Comment:
This is expected and documented behaviour: string to float conversions
will use any valid numeric data at the start of the string and ignore
anything thereafter. The e is being processed because it's being treated
as an exponent.
More information:
http://php.net/language.types.string#language.types.string.conversion
Previous Comments:
------------------------------------------------------------------------
[2010-05-04 15:07:40] daniel dot buschke at nextiraone dot de
Description:
------------
If you convert a string like 8315e839da08e2a7afe6dd12ec58245d into a
float the conversion results in float(INF). The conversion seems to use
only 8315e839 and throws anything else away.
$ php -r 'var_dump(time()+rand()+"8315e839da08e2a7afe6dd12ec58245d");'
float(INF)
Converting this string into a float is - of course - a bug of my PHP
script. But at least I would like to discuss about the conversion
behavior. It is fully correct to convert this string into a float if it
is just "8315e839" but throwing some data away is - from my point of
view - not a valid behavior.
Test script:
---------------
var_dump((float)"8315e839da08e2a7afe6dd12ec58245d");
Expected result:
----------------
false or null or some other invalid "floats" or a warning
Actual result:
--------------
float(INF)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51739&edit=1
Thread (3 messages)