Javascript PMT with FV

D

degroot.ryan

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_value * 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
 
D

degroot.ryan

Oh, some numbers

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


Excel returns 120.98
JS returns 129.39
 
D

degroot.ryan

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(intrest_rate * -(fv-
Math.pow((1+intrest_rate),months)*principal_value)/
(-1+Math.pow((1+intrest_rate),months))*100) / 100;
 
M

MartinRinehart

When doing $ arithmetic, it's best to do your computations in pennies,
then convert to dollars before you display a result.

The discrepancy is probably in nominal/real rate. 1% per month is 12%
per annum, nominal, but it is 12.68% annually real (compounded
monthly).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top