Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
<html>
<head>
<title>Zvonko *</title>
<script>
function getAPR(theForm){
var theLoan = theForm.inpLoan.value*1;
var thePay = theForm.inpRepaiment.value*1;
var theDays = theForm.inpDays.value*1;
theForm.outApr.value="";
if(theLoan&&thePay&&theDays){
theAPR=(thePay-theLoan)/theLoan*100*360/theDays;
theForm.outApr.value=theAPR.toFixed(2);
}
}
</script>
</head>
<body>
<form onKeyUp="getAPR(this)">
<table>
<tr><td>Loan</td><td>
<input type="text" name="inpLoan" ></td></tr>
<tr><td>Repaiment</td><td>
<input type="text" name="inpRepaiment" ></td></tr>
<tr><td>Days</td><td>
<input type="text" name="inpDays" ></td></tr>
<tr><td>APR[%]</td><td>
<input type="text" name="outApr" readonly></td></tr>
</table>
</form>
</body>
</html>
setPPA(52)
function CalcRate() {
var p = getVal(document.input.credit.value);
var i=getVal(document.input.initial.value);
var a=getVal(document.input.repay.value);
var n=Math.floor(getVal(document.input.number.value));
var f=getVal(document.input.last.value);
//Isaac's magic ...
var x=1.0001; var fx=0; var dx=0; var z=0;
do {
fx=i+a*(Math.pow(x,n+1)-x)/(x-1)+f*Math.pow(x,n)-p;
dx=a*(n*Math.pow(x,n+1)-(n+1)*Math.pow(x,n)+1)/Math.pow(x-1,2)+n*f*Math.pow(x,n-1);
z=fx/dx; x=x-z;
//alert("fx="+fx+"\ndx="+dx+"\nz="+z+"\nx="+x)
}
while (Math.abs(z)>1e-9);
r=100*(Math.pow(1/x,m)-1);
document.input.credit.value=TwoDP(p);
document.input.initial.value=TwoDP(i);
document.input.repay.value=TwoDP(a);
document.input.number.value=n;
document.input.last.value=TwoDP(f);
document.getElementById('showapr').innerHTML = "APR : " + OneDP(r) + " %";
document.getElementById('showapr').style.visibility = 'visible';
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Set a time limit on Wordpress Cookie function. | 3 | 16 | |
Dump data from mysql to xls php | 10 | 24 | |
&& operators not performing required logic | 8 | 18 | |
Diff of the day | 2 | 9 |
Join the community of 500,000 technology professionals and ask your questions.