title: PHP float numbers not adding correctly - decimal value missing
body: <p>I am trying to get the total of my variables containing numbers, some may be decimals.  I need this to be to two decimal places and am using the number_format() function.  </p>
  
  <pre><code>$total =  $order-&gt;order-&gt;net+$order-&gt;order-&gt;deductions+$order-&gt;order-&gt;vat+$order-&gt;order-&gt;postage+$order-&gt;order-&gt;postage_tax; 
              echo number_format((float)$total, 2, '.', '');?&gt;
  </code></pre>
  
  <p>I have noticed the following values do not add up correctly and seems to be ignoring the decimal. The total should be 118.50 but instead I get 118.00.</p>
  
  <blockquote>
    <p>100+0+17.5+1+0</p>
  </blockquote>
  
  <p>I have researched this and found the below</p>
  
  <p><a href="http://floating-point-gui.de/basic/" rel="nofollow">http://floating-point-gui.de/basic/</a></p>
  
  <p>I am a little confused by it.  Can anyone explain what I need to do?</p>
  
  <p>*<strong>EDIT</strong>
  Below is dump of the $order variable showing the numbers I am trying to add up.   You can see the 17.5 is 17.5 and not 17.  Is it because they are specified as being strings perhaps?</p>
  
  <p><code>object(SimpleXMLElement)#12 (21) { ["id"]=&gt; string(6) "922704" ["shopkeeper_orderno"]=&gt; string(4) "1001" ["customer"]=&gt; string(6) "797893" ["creationdate"]=&gt; string(16) "29-05-2012 11:55" ["net"]=&gt; string(3) "100" ["vat"]=&gt; string(4) "17.5" ["status"]=&gt; string(1) "1" ["isnew"]=&gt; string(1) "0" ["deductions"]=&gt; string(1) "0" ["postage"]=&gt; string(1) "1" ["paymentmethod"]=&gt; string(20) "PayPal " ["instructions"]=&gt; object(SimpleXMLElement)#17 (0) { } [2]=&gt; object(SimpleXMLElement)#22 (1) { ["items"]=&gt; object(SimpleXMLElement)#30 (9) { ["id"]=&gt; string(7) "1384486" ["headerID"]=&gt; string(6) "922704" ["productID"]=&gt; string(7) "4959678" ["description"]=&gt; string(13) "Wedding dress" ["net"]=&gt; string(3) "100" ["vat"]=&gt; string(4) "17.5" ["qty"]=&gt; string(1) "1" ["formID"]=&gt; string(2) "-1" ["options"]=&gt; object(SimpleXMLElement)#31 (1) { ["options"]=&gt; array(2) { [0]=&gt; object(SimpleXMLElement)#32 (6) { ["id"]=&gt; string(6) "519981" ["orderDetailsID"]=&gt; string(7) "1384486" ["optionid"]=&gt; string(6) "646934" ["optionCost"]=&gt; string(1) "0" ["optionVAT"]=&gt; string(1) "0" ["customText"]=&gt; string(9) "size : 12" } [1]=&gt; object(SimpleXMLElement)#33 (6) { ["id"]=&gt; string(6) "519982" ["orderDetailsID"]=&gt; string(7) "1384486" ["optionid"]=&gt; string(6) "647285" ["optionCost"]=&gt; string(1) "0" ["optionVAT"]=&gt; string(1) "0" ["customText"]=&gt; string(14) "Colour : Ivory" } } } } } } ["postage_tax"]=&gt; string(1) "0" ["dispatched"]=&gt; string(1) "0" ["paybyotherid"]=&gt; string(2) "-1" ["wheredidyouhearid"]=&gt; string(2) "-1"</code> } </p>