• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaScript Function for Calculating Annual Percentage Rate (APR Formula) Read more: JavaScript Func

Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

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.

TOPICS
JavaScript

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

What happens when you use the function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

No results appear. In the console the result is "undefined"

photo.JPG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

This is correct. You defines a function but doesn't use it.

APR();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

with - function APR (num.CD.AmountFinanced, numPaymentsV, num.Financing.RateFinal) - the console result is
SyntaxError: missing) after formal parameters
1: Console: Exec
undefined

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

What want you do with this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Change the last two lines of the function from this:

var aprEst = this.getField("num.CD.APREstimate");
aprEst.value = testrate.toFixed(6);

To this:

event.value = testrate.toFixed(6);

And then call it from the custom Calculation script of "num.CD.APREstimate".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

do you mean so?

image.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Yes, but without the "undefined" part. That's just the output of running it in the console. It should not be a part of the code.

Under the Calculate event just enter:

APR();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

if so the output is "undefined"

image.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

Use the script at calculation of field "num.CD.APREstimate".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2022 Nov 01, 2022

Copy link to clipboard

Copied

We explained how it should be used. It's not clear from these screenshots where you're placing this code. Is this the Console window? If so, that's not how it should be used. If you want help you need to provide the complete details of what you're doing, and what the results are.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

Hi. Yes, I posted the screenshot of the Console window

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2022 Nov 02, 2022

Copy link to clipboard

Copied

LATEST

Using event.value in the console makes no sense.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines