title: Round prices to 10 cents with PHP
body: <p>I have the following code to round Magento products to to nearest $x.90, $x.80, $x.85, etc. but the input is by hand. What I need is a new function to bring the price to the nearest 10 cents by just pushing a button. So if the price is $11,87 I need it to be $11,90, if the price is $11,63 I need it to be $11,60.</p>
  
  <p>How do I do this?</p>
  
  <pre><code>protected function _round($price, $roundTo = 0.00, $type = 'normal')
  {
      $roundTo = ltrim(number_format($roundTo, 2, '.', ''), '0');
  
      if ($type === 'normal') {
          return round($price);
      }
  
      $safety = 99999999;
  
      if ($type === 'up' || ($type === 'down' &amp;&amp; $roundTo &lt; $price)) {
          while(substr($price, -(strlen($roundTo))) != $roundTo) {
  
              if ($type === 'up') {
                  $price += .01;
              }
              else {
                  $price -= .01;
              }
  
              $price = number_format($price, 2, '.', '');
  
              if (--$safety &lt; 1) {
                  throw new Exception('Error');
              }
          }
  
          return $price;
      }
  
      return false;
  }   
  </code></pre>