|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-03-29 11:38 UTC] sniper@php.net
[2005-03-29 12:47 UTC] akorthaus at web dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
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