title: PMT function Payment Type
body: <p>Below is my function to calculate loan payment, 
  As like in Excel I need to add another parameter which is payment type.</p>
  
  <pre><code>function PMT (ir, np, pv, fv ) {
   /*
   ir - interest rate per month
   np - number of periods (months)
   pv - present value
   fv - future value (residual value)
   type - 0 or 1 need to implement that
   */
   pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + fv ) ) / ( ( ir + 1 ) * ( Math.pow ( (ir+1), np) -1 ) );
   return pmt;
  }
  </code></pre>
  
  <p>With Type=0, the interest is computed for 1 month because the payment is assumed to be at the end of the month. For Type=1, the interest is computed for 0 months because the payment is at the beginning of the month.</p>
  
  <p>Can anyone help me to modify the above function with this this PaymentType feature?</p>
  
  <p><a href="http://www.techonthenet.com/excel/formulas/pmt.php" rel="nofollow noreferrer">http://www.techonthenet.com/excel/formulas/pmt.php</a></p>