title: javascript correctly rounding up to two decimals, impossible?
body: <p>In php, we have <code>number_format()</code>. Passing it a value such as:</p>
  
  <pre><code>number_format(3.00 * 0.175, 2);
  </code></pre>
  
  <p>returns <strong>0.53</strong>, which is what I would expect.</p>
  
  <p>However, in JavaScript using <code>toFixed()</code></p>
  
  <pre><code>var num = 3.00 * 0.175;
  num.toFixed(2);
  </code></pre>
  
  <p>returns <strong>0.52</strong>.</p>
  
  <p>Ok, so perhaps <code>toFixed</code> is not what I want...  Maybe something like this...</p>
  
  <pre><code>var num = 3.17 * 0.175;
  var dec = 2;
  Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
  </code></pre>
  
  <p>No, that doesn't work either. It will return 0.56. </p>
  
  <p>How can I get a <code>number_format</code> function in JavaScript that doesn't give an incorrect answer?</p>
  
  <p>Actually I did find an implementation of number_format for js, <a href="http://phpjs.org/functions/number_format" rel="noreferrer">http://phpjs.org/functions/number_format</a>, but it suffers from the same problem.</p>
  
  <p>What is going on here with JavaScript rounding up? What am I missing?</p>