title: automatic currency on textbox in asp.net
body: <p>what i want to happen is to have 12,345.00 rather than 12,345.</p>
  
  <p>here is my code:</p>
  
  <pre><code>&lt;asp:TextBox ID="txtProductPrice" runat="server" onkeyup = "javascript:this.value=Comma(this.value);" class="form-control" MaxLength ="6"&gt;&lt;/asp:TextBox&gt;
  </code></pre>
  
  <p>and the javascript:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
  function Comma(Num) {
      Num += '';
      Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
      Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
      x = Num.split('.');
      x1 = x[0];
      x2 = x.length &gt; 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1))
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
      return x1 + x2;
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>any tricks? thank you</p>