title: Javascript: how to round number to 2 non-zero decimals
body: <p>Without jQuery, how can I round a float number to 2 non-zero decimals (but only when needed - 1.5 instead of 1.50)?</p>
  
  <p>Just like this:</p>
  
  <pre><code>2.50000000004 -&gt; 2.5
  2.652 -&gt; 2.65
  2.655 -&gt; 2.66
  0.00000204 -&gt; 0.000002
  0.00000205 -&gt; 0.0000021
  </code></pre>
  
  <p>I tried this code:</p>
  
  <pre><code>var r = n.toFixed(1-Math.floor(Math.log10(n)));
  </code></pre>
  
  <p>but <code>n=0.00000205</code> implies <code>r=0.0000020</code>, which is in conflict with conditions above.
  But <code>n=0.0000020501</code> implies <code>r=0.0000021</code>, which is OK, so the error is only for 5 as a last decimal, which should be rounded up.</p>