Javascript PMT with FV

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • degroot.ryan@gmail.com

    Javascript PMT with FV

    Hey,

    I'm writing a script that will output a PMT similar to Excel. I've
    searched the net and I've found a code that works, except if a
    FutureValue is required.

    Here's what I found (can't remember where, sorry)

    function pmt_calc( intrest_rate , months , principal_value , fv ) {
    pmt = Math.round( (principal_valu e * intrest_rate) / (1 - Math.pow(1
    + intrest_rate, -months))*100) / 100;
    return pmt;
    }

    Excel's format is :
    Pmt( interest_rate, number_payments , PV, FV, Type )

    Any suggestions on how to locate a possible fix to include
    FutureValue? Or ideas on how to fix it?

    Thanks,
    Ryan
  • degroot.ryan@gmail.com

    #2
    Re: Javascript PMT with FV

    Oh, some numbers

    interest_rate = 0.018125
    months = 24
    principal_value = 2500
    fv = 250


    Excel returns 120.98
    JS returns 129.39

    Comment

    • degroot.ryan@gmail.com

      #3
      Re: Javascript PMT with FV

      Think I found a solution. I'm still going to test it out a bit more,
      but for now, it's working perfect.

      pmt = Math.round(intr est_rate * -(fv-
      Math.pow((1+int rest_rate),mont hs)*principal_v alue)/
      (-1+Math.pow((1+i ntrest_rate),mo nths))*100) / 100;

      Comment

      Working...