title: javascript - Add thousand seperator and retain decimal place
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2901102/how-to-print-number-with-commas-as-thousands-separators-in-javascript">how to print number with commas as thousands separators in Javascript</a>  </p>
  </blockquote>
  
  
  
  <p>I have a function that will add thousand seperators to a number, however it is not working well when a decimal is passed in:</p>
  
  <pre><code>function thousandSep(val) {
          return String(val).split("").reverse().join("")
                        .replace(/(.{3}\B)/g, "$1,")
                        .split("").reverse().join("");
      }
  </code></pre>
  
  <p>If I pass in 10000, I get 10,000 as expected.</p>
  
  <p>However, passing in 10,000.00 I get 1,000,0.00.</p>
  
  <p>How can I modify the function to handle decimals?</p>