[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java Script PMT(rate,nper,pv) function needed

Posted on 2005-04-05
5
Medium Priority
?
2,596 Views
Last Modified: 2008-02-01
Hi everyone,
   This is very urget, I need to calculated PMT (Excel Equivalent for Pmt calculation on Loan) on Client Side for my Web App. Can anyone help.

Thanks

Possibly with following params.. PMT(rate,nper,pv)
0
Comment
Question by:AdilK
  • 2
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
archrajan earned 1000 total points
ID: 13711805
0
 
LVL 19

Expert Comment

by:dakyd
ID: 13711959
Not sure if it's acceptable, but you can use the function below.  The problem with it is that it has a rounding error of less than 1%.  This happens because it doesn't round after every single payment like excel does, so you end up with a different number than excel.  Error is fairly small, though, so you might be able to get away with it - even for a loan of 2 million for 360 monthly payments & 6% annual interest rate, the difference between excel & the below is 30 bucks/month.  For smaller loans like 300K, the error is more like 8 bucks/month.  Hope it helps.

<script>
function calculate(rate, nper, pv)
{
  var numerator = pv * Math.pow((1 + rate),nper);
  var denomFracNum = Math.pow((1 + rate), nper + 1) - 1;
  var denominator = denomFracNum/rate - 1;

  var realAnswer = numerator/denominator;
  document.write(realAnswer.toFixed(2)  + "<br>");
}

calculate(0.005, 360, 200000);
calculate(0.005, 360, 250000);
</script>
0
 

Author Comment

by:AdilK
ID: 13716914
Thanks to both of you. The page refered by archrajan had a link (http://www.mcfedries.com/CreatingAWebPage/mortgage.htm) which had the formula. I tried it and its error is less then what dakyd's was. I am going to try a bit. But thank you both for your time.

Adil
0
 

Author Comment

by:AdilK
ID: 13718412
if any one is ever again interested. This is what I have for the formula. Basically a stripped down version of the formula that was on the page
(http://www.mcfedries.com/CreatingAWebPage/mortgage.htm)


//rate = Interest Rate
//nper = Total Number of Pmts for the loan in Months
//pv = Present Value
function calculatePMT(rate, nper, pv)
{
    princ = pv;
    intRate = (rate/100) / 12;
    months = nper;
    var pmt = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
    return pmt
}

Thanks for the help guys.
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13718419
great.. thanks for taking time to post the answer which worked!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question