From:             php at holycamel dot com
Operating system: linux / apache2
PHP version:      4.3.9RC2
PHP Bug Type:     Math related
Bug description:  Change in behavior with strings containing floats...

Description:
------------
After exploding a string into its components which contain type float,
subsequent multiplication and rounding with those strings doesn't work
unless specifically casting them as type float - ie. (float)$strarray[0]. 


This particularly seems to be the case if the result is < 1.  Where the
result is > 1, the code below seems to work.

This appears to be a recent change in the behavior of php, since previous
versions automatically and correctly interpreted strings as floats where
necessary for related math operations (such as multiplication and
rounding).

This may be my own misconception about how things should work, but I am
reporting it in the event that there has been some problem with the string
type handling introduced in recent versions of php.  If not, sorry for
wasting your time and I'd appreciate an explanation of why our code has
broken.  Thanks.

Reproduce code:
---------------
failing code:
$astr = "2|.9456|.0066778|17"
$numarray = explode("|",$astr);
$result = round($numarray[0] * $numarray[2],4);
echo $result;


working code:
$astr = "2|.9456|.0066778|17"
$numarray = explode("|",$astr);
$result = round((float)$numarray[0] * (float)$numarray[2],4);
echo $result;

(I have had to apply this workaround to code which previously worked with
earlier versions of php without the additional type-casting.)

Expected result:
----------------
.0134

Actual result:
--------------
0

-- 
Edit bug report at http://bugs.php.net/?id=30069&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30069&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30069&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30069&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30069&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30069&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30069&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30069&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30069&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30069&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30069&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30069&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30069&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30069&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30069&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30069&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30069&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30069&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30069&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30069&r=mysqlcfg

Reply via email to