Note that there are some explanatory texts on larger screens.

plurals
  1. POphp number_format gives error message
    text
    copied!<p>I am using php to parse an XML file, but I get an error message when attempting to display a formatted number:</p> <p>Warning: number_format() expects parameter 1 to be double, object given in /home/chesspro/public_html/UNYCL/people-8.php on line 45</p> <pre><code>&lt;?php $xml = simplexml_load_file('Rochester_1.xml'); foreach($xml-&gt;meet as $item) { print '&lt;table class="basic report tableland brown_gradient"&gt;&lt;thead&gt;'; print '&lt;tr&gt;&lt;th class="R-align"&gt;Board&lt;/th&gt;&lt;th class="L-align"&gt;'.$item-&gt;visitor.'&lt;/th&gt;'; $subtotal = 0; foreach($item-&gt;match as $temp) {$subtotal = $subtotal + $temp-&gt;white-&gt;score;} print "&lt;th&gt;" .number_format($subtotal,1). "&lt;/th&gt;"; $subtotal = 0; foreach($item-&gt;match as $temp) {$subtotal = $subtotal + $temp-&gt;black-&gt;score;} print "&lt;th&gt;" .number_format($subtotal,1). "&lt;/th&gt;"; print '&lt;th class="L-align"&gt;'.$item-&gt;home.'&lt;/th&gt;'; print '&lt;/tr&gt;&lt;tbody&gt;'; foreach($item-&gt;match as $game) { print '&lt;tr&gt;&lt;td class="R-align"&gt;'. $game-&gt;board . "&lt;/td&gt;"; print '&lt;td&gt;'. $game-&gt;white-&gt;player."&lt;/td&gt;"; //Here is error: note that number is sometimes 0 $X = $game-&gt;white-&gt;score; print '&lt;td&gt;'. number_format($X) ."&lt;/td&gt;"; print '&lt;td&gt;'. $game-&gt;black-&gt;score."&lt;/td&gt;"; print '&lt;td class="L-align"&gt;'. $game-&gt;black-&gt;player."&lt;/td&gt;"; print "&lt;/tr&gt;";} print '&lt;/table&gt;';} ?&gt; </code></pre> <p>Now can I fix this? I need one point of decimal precision (X.X) although some numbers are integers like "7" which I want to format and display as "7.0" Note that I am using a near current php version 5.3.4</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload