title: Format number to money format in angular
body: <p>I want to convert a number to number format. </p>
  
  <p>I've tried this so far: <a href="http://plnkr.co/edit/lVJGXyuX0BMvB9QUL5zS?p=preview" rel="nofollow">http://plnkr.co/edit/lVJGXyuX0BMvB9QUL5zS?p=preview</a></p>
  
  <pre><code>function formatMoney(credits) {
  
      console.log(credits+'credits');
      var lastThree = credits.substring(credits.length-3);
      // var lastThree = credits.slice(-2);
      var otherNumbers = credits.substring(0,credits.length-3);
      console.log(otherNumbers+'otherNumbers');
      if(otherNumbers !== '')
          lastThree = ',' + lastThree;
      var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
      return res;
    }
  
  function formatNumber(num) {
      var n1, n2;
      num = (Math.round(num * 100) / 100) + '' || '';
      n1 = num.split('.');
      n2 = n1[1] || null;
      n1 = n1[0].replace(/(\d)(?=(\d\d)+\d$)/g, ",");
      num = n2 ? n1 + '.' + n2 : n1;
      return num;
    }
  </code></pre>
  
  <p>I want to convert the number to Indian currency. </p>
  
  <p>Example: </p>
  
  <pre><code>1,000
  10,000
  1,00,000
  10,00,000
  </code></pre>
  
  <p>The output that I am getting with function formatMoney(): 1,0,0,000</p>
  
  <p>The output that I am getting with function formatNumber(): 1,000 and after pressing 0, it changes to NaN0</p>
  
  <p>What am I doing wrong here?</p>