
Help math.pow
Ok I have An initial amount 10,000.00 with an interest rate of 10% on a 3 year term wich comes to a total of 13,310.00 compounded at the end of 3 years now I need to calculate the agent commision witch is 2%, so basically first year he makes 220.00 2nd year 242.00 3rd year 266.20 total 728.20.bassically at the end of the year I need to calculate the 2% commision of the initial maount with the interest. also the terms are selected by user 1,2 or 3 years how do I calculate this if 2 years selected show commission 242.00 etc<BR><BR>I have some code but can't seem to get those figures can anybody please help me out<BR><BR>Thanx<BR>AJ<BR>intrate = 10%<BR>comm = 2%<BR>invamnt = 10,000.00<BR><BR><BR>for (i=0;i<years;i++) {<BR> var inttotal = Math.round((invamnt*(Math.pow((1+intrate/100),years))invamnt)*100)/100;<BR> var invmattotal = invamnt + inttotal;<BR> var commtotal = Math.round((invmattotal*(Math.pow((1+comm/100),years))invmattotal)*100)/100;<BR>}

You don't need Math.pow
Since you want to use a loop to get the annual commisions, you *SHOULDN'T* use Math.pow. That formula you are playing with is how you *avoid* using a loop.<BR><BR>var intratePct = 10;<BR>var commPct = 2;<BR>var invamnt = 10000.0;<BR>var years = 3;<BR><BR>var totalamnt = invamnt;<BR>var totalcomm = 0;<BR><BR>var intrate = intratePct / 100.0;<BR>var comm = commPct / 100.0;<BR><BR>for ( yrnum = 1; yrnum <= years; ++yrnum ) <BR>{<BR> var yrint = totalamnt * intrate;<BR> totalamnt += yrint;<BR> var yrcomm = Math.round( totalamnt * comm );<BR> alert("Commission for year #" + yrnum + " is " + yrcomm);<BR> totalcomm += yrcomm;<BR>}<BR>

RE: You don't need Math.pow
well Not that I really want to use the loop I just thought I had to. If you don't mind How can I do this with the math.pow()<BR><BR>Thanx<BR>AJ

I don't see a way...
..to get the commission correct and use Math.pow().<BR><BR>[Well, you *could* use Math.pow() just to get the ending total amount, but what's the point? Since you'll need to do the loop to get the correct commissions? It's pointless.]<BR><BR>

RE: I don't see a way...
I just finished with what you gave me and it works beatifully Thanx for the help I owe you a nice cold one.And for two cold ones maybe you can tell me how I could get the interest amount of the initial investment to date.Bassically if user logs in and looks at his account show him how much interest he has accumulated to that day.<BR><BR>Thanx<BR>AJ

To the day?
Didn't we have this discussion a week or two ago??<BR><BR>How accurate does it need to be?<BR><BR>Let's see...<BR><BR>You can get pretty close by using the annual interest rate divided by 365.25 and then using the Math.pow formula for the number of days instead of number of years.<BR><BR>You can figure the number of days by using Date.getTime() method, which gives # of milliseconds since some start time. Subtract the results of using getTime() with today and using getTime() with the start date of the investment. Divide by number of milliseconds in one day to get # of days.<BR><BR>

RE: To the day?
Yeah you did explain it to me roughly but I wasn't able to get it to work.But I'll keep on trying. Maybe with this more detailed explanation I'll get it.<BR>Thanx alot for your help.<BR>AJ

Oh, nuts!
I just realized!<BR><BR>If you do as I suggested, then you will get a much higher interest paid than you suggest. <BR><BR>That's because that formula you are using with Math.pow( ) *assumes* that you are compounding at a rate that matches the length of the period!<BR><BR>So if you use days, then it assumes you are compounding DAILY!<BR><BR>And (just to pick an example) 10% annual rate, when compounded daily, works out to an "Annual Percentage Yield" of about 10.5%!!!!<BR><BR>Ever noticed how some banks will advertise two rates on savings deposits? One an annual rate and the other an annual *YIELD*? That is what this is all about!<BR><BR>So if this investment doesn't do thatif it really *DOES* pay a simple annual interest ratethen you don't need to go to that much trouble. You can simply calculate the annual amount for the last year that includes today's date and prorate the interest based on the number of days.<BR><BR>Well...that's actually *harder* to calculate! But it's logically simpler.<BR><BR>

I'm Confused
yoou're getting me even more confused. I knew I should have payed attention in math class.<BR>Thanx for the advice I'll figure it out some how.

Here...
<HTML><BODY><BR><BR><FORM ><BR>What was the investment amount? <INPUT Name="Amt"><BR><P><BR>What day did investment start? <INPUT Name="Start"><BR><P><BR>What was interest rate? <INPUT Name="Rate"><BR><P><BR><INPUT Type=Button Value="Calculate interest to date" onClick="calc(this.form);"><BR><P>< BR>Interest to date <INPUT Name="IntToDate" ReadOnly Value="0"><BR><P><BR>Total to date <INPUT Name="TotalToDate" ReadOnly Value="0"><BR></FORM><BR><BR><SCRIPT><BR>function calc(frm)<BR>{<BR> var amt = parseFloat(frm.Amt.value);<BR> var start = new Date( frm.Start.value);<BR> var rate = parseFloat(frm.Rate.value);<BR> if ( isNaN(amt)  isNaN(Date.parse(frm.Start.value))  isNaN(rate) )<BR> {<BR> alert("Bad value(s)");<BR> return;<BR> }<BR> var today = new Date();<BR> today.setHours(0);<BR> today.setMinutes(0);<BR> today.setSeconds(0);<BR> today.setMilliseconds(0);<BR><BR> // fix rate<BR> rate /= 100.0;<BR> <BR> // diff between two dates in ms:<BR> var ms = today.getTime()  start.getTime();<BR> // and in days<BR> var days = ms / ( 24 * 60 * 60 * 1000 );<BR> var yrs = Math.floor( days / 365.25 );<BR> days = yrs * 365.25; // days remaining in last year<BR><BR> var tty = amt; // total to this year<BR> if ( yrs > 0 ) tty = amt * Math.pow( 1 + rate, yrs );<BR><BR> var iy = rate * tty; // interest that would be earned this year<BR> // add whole years' interest to proportionate for this year<BR> var itd = (ttyamt) + ( iy * ( days / 365.25 ) ); <BR><BR> frm.IntToDate.value = itd;<BR> frm.TotalToDate.value = amt + itd;<BR>}<BR></SCRIPT><BR><BR></BODY></HTML><BR><BR>*****************<BR><BR>It' ;s not exact (doesn't take into account actual # of days per year), but it's really close. Within pennies on a $1000 investment, for example.<BR><BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

