title: regex format string number with commas and 2 decimals in javascript
body: <p>I have a string <code>n</code> which is a number.
  The following adds the commas where needed, but I also want to change the number of decimals.  It should also round where appropriate.</p>
  
  <pre><code>var parts = n.split(".");
  var num = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : "");
  </code></pre>
  
  <p>This turns a number like <code>1234.567</code> in to <code>1,234.567</code>.
  But I need my number to look like: <code>1,234.57</code></p>
  
  <p>I tried taking <code>parts[1]</code> and converting to a Number, then rounding, then concatenating it back; but that is error prone.</p>
  
  <p>How can I get this result by altering my regex? Thanks.</p>