title: parseFloat rounding
body: <p>I have javascript function that automatically adds input fields together, but adding numbers like 1.35 + 1.35 + 1.35 gives me an output of 4.050000000000001, just as an example. How can I round the total to the second decimal instead of that long string? </p>
  
  <p>The input fields will have more than just the 1.35 example so I need the total to never have more than 2 points after the decimal. Here is the full working code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  function Calc(className){
  var elements = document.getElementsByClassName(className);
  var total = 0;
  
  for(var i = 0; i &lt; elements.length; ++i){
  total += parseFloat(elements[i].value);
  }
  
  document.form0.total.value = total;
  }
  
  function addone(field) {
    field.value = Number(field.value) + 1;
    Calc('add');
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="form0" id="form0"&gt;
  1: &lt;input type="text" name="box1" id="box1" class="add" value="0" onKeyUp="Calc('add')" onChange="updatesum()" onClick="this.focus();this.select();" /&gt;
  &lt;input type="button" value=" + " onclick="addone(box1);"&gt;
  &lt;br /&gt;
  
  2: &lt;input type="text" name="box2" id="box2" class="add" value="0" onKeyUp="Calc('add')" onClick="this.focus();this.select();" /&gt;
  &lt;input type="button" value=" + " onclick="addone(box2);"&gt;
  &lt;br /&gt;
  
  &lt;br /&gt;
  Total: &lt;input readonly style="border:0px; font-size:14; color:red;" id="total" name="total"&gt;
  &lt;br /&gt;
  &lt;/form&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Some things I have tried, which should work but I am clearly implementing them incorrectly:</p>
  
  <pre><code>for(var i = 0; i &lt; elements.length; ++i){
  total += parseFloat(elements[i].value.toString().match(/^\d+(?:\.\d{0,2})?/));
  
  var str = total.toFixed(2);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>for(var i = 0; i &lt; elements.length; ++i){
  total += parseFloat(elements[i].value * 100) / 100).toFixed(2)
  </code></pre>
  
  <p>Have also had no luck with <code>Math.floor</code></p>