ID: 32479
Updated by: [EMAIL PROTECTED]
Reported By: akorthaus at web dot de
-Status: Open
+Status: Closed
Bug Type: SimpleXML related
Operating System: Linux 2.4.28 (Gentoo)
PHP Version: 5.0.3
New Comment:
Works with latest CVS. (you need to cast the stuff to float / string
though)
Previous Comments:
------------------------------------------------------------------------
[2005-03-29 10:44:46] akorthaus at web dot de
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 this bug report at http://bugs.php.net/?id=32479&edit=1