|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2011-06-01 22:18 UTC] bphelpsen at gmail dot com
 Description:
------------
When an XML node value is an integer SimpleXML always casts it to an int, even if its a float or double.
Test script:
---------------
<?php
$xml = simplexml_load_string("<xml><number>214748364800</number></xml>");
echo $xml->number . "\n"; // the proper number
$int = $xml->number / 1024 / 1024 / 1024; // initial cast to an int causes problems
echo $int . "\n"; 
$double = (double) $xml->number / 1024 / 1024 / 1024; // hard cast to a double fixes it
echo $double . "\n";
?>
Expected result:
----------------
214748364800
200
200
Actual result:
--------------
214748364800
1.9999999990687
200
PatchesPull Requests
Pull requests: 
 HistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
$stdobj= new stdClass; $stdobj->Price='.53'; echo 1+$stdobj->Price; output: object(stdClass)#1 (1) { ["Price"]=> string(3) ".53" } 1.53 This shows that the standard class is correctly juggled from a string to a float when added to an integer. This is in contrast to other comments that suggested that the reported behavior is to be expected.