title: Number Formatting for large integer numbers in Javascript
body: <p>I know there are in-build function in javascript like <code>toLocalString()</code> to achieve number formatting. But this question is purely for learning and logic understanding. </p>
  
  <p>I have a function in javascript that formats given number in Indian Number formatting standards (eg: 1,234 | 12,21,123 | etc)</p>
  
  <p><strong>Code</strong> </p>
  
  <pre><code>function formatter(input) {
  
      var inputStr = input.toString(), l = inputStr.length;
      var c = 1, f = 0;
  
      console.log(l);
  
      for (var x=l-1; x&gt;=0; x--) {
  
          if (x === 0) {
              continue;
          }
  
          if (c === 3 &amp;&amp; f === 0) {
              inputStr = inputStr.substring(0, x) + ',' + inputStr.substring(x);
              f = 1;
              c = 0;
          } else if (c % 2 === 0 &amp;&amp; f === 1) {
              inputStr = inputStr.substring(0, x) + ',' + inputStr.substring(x);
              c = 0;
          }
  
          c++;
      }
  
      return inputStr;
  }
  </code></pre>
  
  <p>Now this works for most part (as far as I have test, do point out bugs if you spot any). But my question is how do I handle large number in this, i.e. how do I handle values greater than 9007199254740991.</p>