Link to home
Start Free TrialLog in
Avatar of it31
it31

asked on

Urgent: Javascript PMT Function()

In the visual basic and excel have a function call pmt(), it can calculator payment.

This is VB sample command:
lvTotInterest = Format(Pmt(0.0575 / 12, 300, 200000 * -1), "#########.00")

The answer will come out: 1258.21

So how about javascript?

Will increase the points to 300 points by later.

Thanks
Avatar of Alopederii
Alopederii

P.S. -- I don't think that there is a JavaScript solution without having to create a function (which the sites above might help with)
if I had the calculations, I could throw it together pretty quickly, but I'm not up for searching out the calculations of what you need. I presume 1258.21 is the amt you pay each time.... where the first number (.0575/12) is the monthly interest and 200000 is the total value taken out on loan while 300 is the number of payments. If this is correct and you can link me to a formula or provide me with the formula, I will gladly throw something together.
I'm not too sure where you want to go with it, but try this:


<script>
function Pmt(r,np,pv,fv) {
r = r/1200
if (!fv) fv = 0;
pmt=-(r * (fv+Math.pow((1+r),np)*pv)/(-1+Math.pow((1+r),np)));
finalPmt=roundOff(pmt,2);
alert(finalPmt);
}

function roundOff(value, dplaces){
value=value.toString()

if((value.indexOf(".")!=-1)&&(value.length>(value.indexOf(".")+dplaces))){
    three=value.substring(value.indexOf(".")+dplaces+1,value.indexOf(".")+dplaces+2)
    one=value.substring(0,value.indexOf(".")+dplaces)
    two=value.substring(value.indexOf(".")+dplaces,value.indexOf(".")+dplaces+1)
    if(parseInt(three)>=5){value=one+(parseInt(two)+1);value=parseFloat(value)}
    else{value=one+two;value=parseFloat(value)}
}
       return value;
}

</script>

<body onLoad="Pmt(5.75,300,-200000);">
If your needing it to parse forms or something for a form based calculator, let me know.
Avatar of it31

ASKER

kenny9336,

Thank you for the reply, it look like can work.

And are you have the function for PPmt in javascript?

I will increase the points after EE Support Team delete my other Unlock Question, thanks.
i gotta look up the formula for it and write the code, but I can do it.
hmm.. i'm having a slight difficulty finding this formula.. anyone got a economics book?
ASKER CERTIFIED SOLUTION
Avatar of kenny9336
kenny9336

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial