Bug #74167 [Com]: intval() considers string input as integer if string contains e(e notation)
| From: | spam2 at rhsoft dot net | Date: | Sat, 25 Feb 2017 18:22:36 +0000 |
| Subject: | Bug #74167 [Com]: intval() considers string input as integer if string contains e(e notation) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207549@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74167&edit=1
ID: 74167
Comment by: spam2 at rhsoft dot net
Reported by: stephin at stephin dot in
Summary: intval() considers string input as integer if string
contains e(e notation)
Status: Open
Type: Bug
Package: Strings related
PHP Version: 7.1.2
Block user comment: N
Private report: N
New Comment:
this is for most cases a bugfix where before PHP7.1 when something returned scientific notation
because of 0.0000000000001 you got weird results and lost data
i have some workarounds in several scripts to prevent that which are ugly
if(strpos($out, 'E') || strpos($out, 'e'))
{
$out = rtrim(number_format((float)$out, 20), '0');
}
http://php.net/manual/de/migration71.incompatible.php
Numerical string conversions now respect scientific notation
Integer operations and conversions on numerical strings now respect scientific notation. This also
includes the (int) cast operation, and the following functions: intval() (where the base is 10),
settype(), decbin(), decoct(), and dechex()
Previous Comments:
------------------------------------------------------------------------
[2017-02-25 18:10:04] stephin at stephin dot in
Description:
------------
php -r "echo intval('1e10');"
expected output: 1
actual output: 10000000000
i have tested this in some of other previous version series and found only php 7.1.x have this bug.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74167&edit=1