title: jQuery function to to format number with commas and decimal
body: <p>I'm using the following function to format numbers as the user types. It will insert a comma every 3 numbers. Ex: <code>45696.36</code> becomes <code>45,696.36</code>.</p>
  
  <p>However, I've run into a problem with it. If the numbers after the decimal are longer than 3 digits, it starts adding commas to them. Ex: <code>1136.6696</code> becomes <code>1,136.6,696</code>.</p>
  
  <p>This is my function:</p>
  
  <pre><code>$.fn.digits = function(){
    return this.each(function() {
      $(this).val( $(this).val().replace(/[^0-9.-]/g, '') );
      $(this).val( $(this).val().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); 
    }) 
  }
  </code></pre>
  
  <p>How can I fix this so it stops placing commas after the decimal? I'm using jQuery 1.8. Thanks!</p>