Bug #48573 [Opn->Csd]: E-notated strings improperly cast as integers

From: Date: Tue, 24 Oct 2017 18:36:51 +0000
Subject: Bug #48573 [Opn->Csd]: E-notated strings improperly cast as integers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212291@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48573&edit=1 ID: 48573 Updated by: jhdxr@php.net Reported by: josh at mykoala dot com Summary: E-notated strings improperly cast as integers -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Mac OS X 10.5.7 PHP Version: 5.2.9 -Assigned To: +Assigned To: jhdxr Block user comment: N Private report: N New Comment: Thank you for your bug report. This issue has already been fixed in the latest released version of PHP, which you can download at http://www.php.net/downloads.php fixed since 7.1.0, see https://3v4l.org/ojX04 Previous Comments: ------------------------------------------------------------------------ [2009-06-23 20:14:44] 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");' float(564014.18785) It's that conversion to int directly that makes Iron Eyes Cody cry. ------------------------------------------------------------------------ [2009-06-23 19:57:29] 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";' 564014.18785 ------------------------------------------------------------------------ [2009-06-16 19:54:37] 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-16 19:08:10] josh at mykoala dot com Description: ------------ 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");' int(5) $ php -r 'var_dump((int)5.6401418785e+05);' int(564014) $ php -r 'var_dump((int)(float)"5.6401418785e+05");' int(564014) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=48573&edit=1

« previous php.bugs (#212291) next »