#31889 [Opn->Csd]: Strings of the format -.55 are not converted to numbers correctly

From: Date: Tue, 08 Feb 2005 23:07:48 +0000
Subject: #31889 [Opn->Csd]: Strings of the format -.55 are not converted to numbers correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-73675@lists.php.net to get a copy of this message
ID: 31889 Updated by: tony2001@php.net Reported By: justinpatrin@php.net -Status: Open +Status: Closed Bug Type: Unknown/Other Function Operating System: Linux PHP Version: 4.3.10 New Comment: Fixed in snapshot -> closed. Previous Comments: ------------------------------------------------------------------------ [2005-02-09 00:04:40] justinpatrin@php.net Ok, you're right, my code is broken, I should have (float) instead of (int). Stupid me. And that fixes that code. However, consider this code: $str = '-.55'; $num = $num2 = 0; $num += $str; $num2 += (float)$str; echo $str."\n".(float)$str."\n".$num."\n".$num2."\n"; This outputs: -.55 -0.55 0 -0.55 But should output: -.55 -0.55 -0.55 -0.55 The snapshot fixes this, thanks. ------------------------------------------------------------------------ [2005-02-08 23:37:10] tony2001@php.net Please try using this CVS snapshot: http://snaps.php.net/php4-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-STABLE-latest.zip ------------------------------------------------------------------------ [2005-02-08 23:35:11] helly@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php read your code again ------------------------------------------------------------------------ [2005-02-08 22:49:30] justinpatrin@php.net Description: ------------ A string which holds a number which is less than 0 but greater than -1 and does not have a leading 0, is not converted to a number correctly, it comes back as 0. Reproduce code: --------------- $str = '-.55'; echo $str."\n".(int)$str; Expected result: ---------------- -.55 -.55 Actual result: -------------- -.55 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31889&edit=1

« previous php.bugs (#73675) next »