title: PHP rounding Exchange Rate Conversions
body: <p>Why is PHP rounding my figures down?  </p>
  
  <p>I need to obtain more accurate results, not rounding down the figures, how do I achieve this?</p>
  
  <p>Here is the code;</p>
  
  <pre><code>    /// Get Exchange Rates
          $exchange_rates = "exchange_rates.xml";
          if(time()-filemtime($exchange_rates)&gt;24*3600){
           $dom = new DOMDocument();
           $dom-&gt;load('http://www.floatrates.com/daily/gbp.xml');
           $dom-&gt;save($exchange_rates);
          }
  
      /// Work with the following Exchange Rates
          $exchange_rates_required = array("AUD","EUR","USD","CAD","JPY","SEK","NOK");
  
      /// Loop through remaining currencies and convert figure
          if(file_exists($exchange_rates)){
           $exchange_rates_xml = simplexml_load_file($exchange_rates);
           foreach($exchange_rates_xml as $val){
            if(in_array($val-&gt;targetCurrency,$exchange_rates_required)){
             $price = 10.00; 
             $rate = $val-&gt;exchangeRate; 
             echo $price . "\t " . $rate . "\t" . ($rate*$price) . "\n";
            }
           }
          }
  </code></pre>
  
  <p>Data;</p>
  
  <pre><code>    USD  10  1.24658358     10
      EUR  10  1.17132961     10
      CAD  10  1.67421309     10
      AUD  10  1.68093433     10
      JPY  10  138.04769510   1380
      NOK  10  10.62606016    100
      SEK  10  11.47199056    110
  </code></pre>