title: How to round and sum up decimals in javascript?
body: <p>On my website I have a form like this:</p>
  
  <pre><code>&lt;select id="payments" multiple="multiple"&gt;
    &lt;option data-amount="23.1" value="1"&gt;Invoice 1&lt;/option&gt;
    &lt;option data-amount="25.3" value="2"&gt;Invoice 2&lt;/option&gt;
    &lt;option data-amount="50.0" value="3"&gt;Invoice 3&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>And a little dash of Javascript:</p>
  
  <pre><code>$(function() {
  
      // Sum up and insert open_amount into 'amount' field depending on what invoice numbers are selected
      $("#payments").change(function() {
          var sum = 0;
          $('#payments :selected').each(function() {
              sum += Number($(this).data("amount"));
          });
          $("#payment_amount").val(sum);
      });
  
  });
  </code></pre>
  
  <p>The problem is that I sometimes get weird numbers like <code>48.400000000000006</code> where I actually want rounded results with two decimal places.</p>
  
  <p>How can I properly sum up all the selected amounts?</p>