JavaScript Function for Calculating Annual Percentage Rate (APR Formula) Read more: JavaScript Func
Hi
I am looking for a javascript function to calculate the Annual Percentage Rate (APR).
On this page https://answers.acrobatusers.com/Formula-loan-interest-rate-q176800.aspx
I found a post from a user explaining the function needed to calculate the APR rate.
I copied this function to the console of my pdf file
function APR ()
{var paymentV = + getField ("num.CD.Monthly.P & I"). value; // MONTHLY P&I PAYMENT
var numPaymentsV = + getField ("num.numPayments"). value; // NUMBER OF PAYMENTS, DURATION OF THE LOAN
var rateLoanV = + getField ("num.Financing.RateFinal"). value; // INTEREST RATE LOAN
var financedV = + getField ("num.CD.AmountFinanced"). value; // AMOUNT OF THE LOAN LESS ADVANCE COSTS
var rateV = rateLoanV / 12; // convert annual rate to rate
var testrate = rateV;
var iteration = 1;
var testresult = 0; // iterate until result = 0
var testdiff = testrate;
while (iteration <= 100)
{testresult = ((testrate * Math.pow (1 + testrate, numPaymentsV)) / (Math.pow (1 + testrate, numPaymentsV) - 1)) - (paymentV / financedV);
if (Math.abs (testresult) <0.0000001) break;
if (testresult <0) testrate + = testdiff;
else testrate - = testdiff;
testdiff = testdiff / 2;
iteration ++;}
testrate = testrate * 12;
var aprEst = this.getField ("num.CD.APREstimate");
aprEst.value = testrate.toFixed (6);}
In the pdf file I have inserted these fields
num.CD.Monthly.P & I = 489
num.numPayments = 300
num.Financing.RateFinal = 0.03
num.CD.AmountFinanced = 100,000
The result from the console is undefined
Please, can anyone help me to set the function correctly?
Or, does anyone know the correct function to calculate the APR rate.
