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

Posted on 2005-04-05
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.


Possibly with following params.. PMT(rate,nper,pv)
Question by:AdilK
    LVL 25

    Accepted Solution

    LVL 19

    Expert Comment

    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.

    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);

    Author Comment

    Thanks to both of you. The page refered by archrajan had a link ( 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.


    Author Comment

    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

    //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.
    LVL 25

    Expert Comment

    great.. thanks for taking time to post the answer which worked!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    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…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now