Enjoy an ad free experience by logging in. Not a member yet? Register.


Results 16 to 21 of 21

02192013, 11:21 PM #16
Pardon me, but that's a clumsy way to do it.
And it doesn't really answer the question. You'd still have to add up the interest paid from payment number XXX to the end of the loan.An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

02202013, 08:55 AM #17

02202013, 12:16 PM #18
 Join Date
 May 2012
 Location
 France
 Posts
 216
 Thanks
 0
 Thanked 29 Times in 27 Posts
I do not understand clumsy but it's our official method ! See this page
NB : With the wrong banker's methods, the real rate is not 12% (to take your example) but Math.pow(1.01,12) which is 12,68% !Last edited by 007julien; 02202013 at 12:24 PM.

02202013, 12:53 PM #19
 Join Date
 Jun 2002
 Location
 London, England
 Posts
 17,730
 Thanks
 202
 Thanked 2,508 Times in 2,486 Posts
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

02202013, 07:30 PM #20
It's clumsy because to answer the original question what you have to do is
(1) Run the loop from the first period to the period number in question and then throw away any results you get from that.
(2) Continue the loop to the end, summing up the individual interest amounts.
(3) Present the final sum.
In other words, you perform a whole bunch of operations just to get the same sum you can get via two calculations using the code I showed. (I presented it in several lines of code, for clarity, but there are really only 2 lines of codeother than getting and validating the input and displaying the resultneeded.)
Oh, what the heck:
Code:form.calc.onclick = function( ) { var pv = Number(form.loan.value); var periods = Number(form.months.value); var annual = Number(form.apr.value); var rate = Number(form.remaining.value) / 12 / 100; if ( isNaN(pv)  isNaN(periods)  isNaN(rate)  isNaN(remain) ) { alert("All values must be numbers"); // alert obsolete, bad usage return; } var pmt = pv / ( ( 1  Math.pow( 1 + rate,  periods ) ) / rate ); var rintTotal = pmt * remain  pmt * ( ( 1  Math.pow( 1 + rate,  remain ) ) / rate ); document.getElementById("rintTotal").innerHTML = rinttotal.toFixed(2); }
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

02202013, 07:39 PM #21
Eehhh... Okay, maybe it isn't all that clumsy. And if you don't understand or don't know the need formulas then I suppose it's easier to grasp.
Code:form.calc.onclick = function( ) { var pv = Number(form.loan.value); var pmt = Number(form.payment.value); // NEW! var periods = Number(form.months.value); var annual = Number(form.apr.value); var rate = Number(form.remaining.value) / 12 / 100; if ( isNaN(pv)  isNaN(pmt)  isNaN(periods)  isNaN(rate)  isNaN(remain) ) { alert("All values must be numbers"); // alert obsolete, bad usage return; } var inttotal = 0; for ( var p = 1; p <= periods; ++p ) { var ipaid = pv * rate; if ( p > periods  remain ) { inttotal += ipaid; } pv = ( pmt  ipaid ); } document.getElementById("rintTotal").innerHTML = rinttotal.toFixed(2); }
If it's not supplied, then you have to add in my line to calculate the payment.
And so then you need all the code in red IN ADDITION TO my payment calc.An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.