title: Decimal odds conversion timeout
body: <p>I'm trying to convert from decimal to fraction sporting odds. I have found via a search a PHP function which works well, but certain decimals cause problems, such as 2.1 which maxs out the server:</p>
  
  <pre><code>    function dec2frac($dec) { 
  
          $decBase = --$dec; 
  
          $div = 1; 
  
          do { 
  
              $div++; 
  
              $dec = $decBase * $div; 
  
          } while (intval($dec) != $dec); 
  
          if ($dec % $div == 0) { 
              $dec = $dec / $div; 
              $div = $div / $div; 
          } 
  
          return $dec.'/'.$div; 
  
      } 
  
  $decimal = 2.3;
  
  echo $decimal.' --&gt; '.dec2frac($decimal);
  </code></pre>
  
  <p>A decimal odds of 6 should give 5/1. This is calulated as 6-1=5 = 5/1</p>
  
  <p>I have found that decimal input of 2.2 and 2.3 trips the function up but other values seem to be ok. What is causing this anomaly, is there way around it?</p>
  
  <p>Thanks. </p>