#32479 [NEW]: number-strings in xml are converted to int, not float

From: Date: Tue, 29 Mar 2005 08:44:46 +0000
Subject: #32479 [NEW]: number-strings in xml are converted to int, not float
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-75969@lists.php.net to get a copy of this message
From: akorthaus at web dot de Operating system: Linux 2.4.28 (Gentoo) PHP version: 5.0.3 PHP Bug Type: SimpleXML related Bug description: number-strings in xml are converted to int, not float Description: ------------ If I want to calculate with numbers (decimals) from an xml file/string parsed by simplexml, php does not convert these strings (e.g. "1.2") to float (1.2), it converts them to integer (1). Reproduce code: --------------- <?php $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <test> <num>1.2</num> <num>0.2</num> <num>0.5</num> </test> XML; $xml = simplexml_load_string($xmlstr); foreach ($xml->num as $number) { echo $number, " * 3 = ", $number * 3, "\n"; echo "var_dump: ", var_dump($number), "\n"; } $number_array = array('1.2', '0.2', '0.5'); foreach ($number_array as $number) { echo $number, " * 3 = ", $number * 3, "\n"; echo "var_dump: ", var_dump($number), "\n"; } ?> Expected result: ---------------- The following loop: foreach ($xml->num as $number) { echo $number, " * 3 = ", $number * 3, "\n"; } should display: 1.2 * 3 = 3.6 0.2 * 3 = 0.6 0.5 * 3 = 1.5 (as it actually works with $number_array) Actual result: -------------- 1.2 * 3 = 3 0.2 * 3 = 0 0.5 * 3 = 0 -- Edit bug report at http://bugs.php.net/?id=32479&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32479&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32479&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32479&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32479&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32479&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32479&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32479&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32479&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32479&r=support Expected behavior: http://bugs.php.net/fix.php?id=32479&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32479&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32479&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32479&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32479&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32479&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32479&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32479&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32479&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32479&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32479&r=mysqlcfg

« previous php.bugs (#75969) next »