title: How to format a number large number as a string using JavaScript
body: <p>I coded the following quick loan calculator using online tutorials and stuff as I have very basic coding skills. It works perfectly, the only thing that I need changed is that all three the output amounts needs spaces in the numbers... for example, it should output "400 000" instead of "400000". How can I add a space or a coma to make the large numbers more readable?</p>
  
  <pre><code>&lt;form oninput="loanval.value=loan.value; periodval.value=period.value; paymentval.value=Math.floor(loan.value / period.value)"&gt;
  
  &lt;label&gt;Loan Amount&lt;/label&gt;
  &lt;input type="range" id="loan" name="loan" min="5000" max="400000" step="5000"&gt;              
  &lt;output name="loanval" for="loan"&gt;0&lt;/output&gt;
  
  &lt;label&gt;Loan Period&lt;/label&gt;
  &lt;input type="range" id="period" name="period" min="1" max="15"&gt;          
  &lt;output name="periodval" for="period"&gt;0&lt;/output&gt;
  
  &lt;label&gt;Your monthly repayment will be:
  &lt;output name="paymentval"&gt;0&lt;/output&gt;
  
  &lt;/form&gt;
  </code></pre>