title: How to format currency while typing, but you also want to use that input as a number after formatting (jQuery/Javascript)
body: <p>I am trying to build an online calculator and I wanted to format my input into currency while typing.</p>
  <p>On this website: <a href="https://www.ratehub.ca/cmhc-mortgage-insurance" rel="nofollow noreferrer">https://www.ratehub.ca/cmhc-mortgage-insurance</a> the asking price input box is similar to what I would like to achieve.</p>
  <p>I have tried this code here:</p>
  <pre><code>$(&quot;#formattedNumberField&quot;).on('keyup', function(){
  var n = parseInt($(this).val().replace(/\D/g,''),10);
  $(this).val(n.toLocaleString());
  //do something else as per updated question
  myFunc(); //call another function too
  });
  </code></pre>
  <p>But it would display NaN after typing a number and deleting it, also I can not use the formatted number for future calculation.</p>
  <p>Any help would be appreciated!</p>