|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48573 E-notated strings improperly cast as integers
Submitted: 2009-06-16 19:08 UTC Modified: 2017-10-24 18:36 UTC
From: josh at mykoala dot com Assigned: jhdxr (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Mac OS X 10.5.7
Private report: No CVE-ID: None
 [2009-06-16 19:08 UTC] josh at mykoala dot com
When an E notated integer is in a string, and you try to cast it to an integer, the value stops at anything non-integer, reducing the ability to cast notated numbers.  It does not first check or convert the value to a float to account for E notation.

The documentation on type juggling doesn't mention this limitation, and it is not the expected result.

Reproduce code:
$ php -r 'var_dump((int)"5.6401418785e+05");'
$ php -r 'var_dump((int)5.6401418785e+05);'
$ php -r 'var_dump((int)(float)"5.6401418785e+05");'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-16 19:54 UTC] josh at mykoala dot com
> When an E notated integer

When an E notated float*

intval() on the string also (predictably) produces the same result as casting to int
 [2009-06-23 19:57 UTC] sjoerd-php at linuxonly dot nl
Thank you for your bug report.

A workaround for what you want is adding 0:
php -r 'echo 0 + "5.6401418785e+05";'
 [2009-06-23 20:14 UTC] josh at mykoala dot com
Well, round() produces the desired result -- the large number without any decimals.  Adding zero just casts to float, which takes the decimals into consideration, and is the same as:

$ php -r 'var_dump((float)"5.6401418785e+05");'

It's that conversion to int directly that makes Iron Eyes Cody cry.
 [2017-10-24 18:36 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: jhdxr
 [2017-10-24 18:36 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

fixed since 7.1.0, see
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC