Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- How to calculate "Future Value" of an investment?

Jul 23, 2017

Copy link to clipboard

Copied

Does anyone now the javascript formula to have a form field in Adobe Acrobat Pro calculate "Future Value" given present value, years & interest?

You are not passing the values for the parameters of the function in the function call. It looks like you are also trying to define the function when you are setting the events. value.

I would create a document level script named "FV" and place the following code into script.

function FV(rate, nper, pmt, pv, type) {

var pow = Math.pow(1 + rate, nper), fv;

if (rate) {

fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow;

} else {

fv = -1 * (pv + pmt * nper);

}

return fv.toFixed(2);

}

For the field calculation I would use the following code:

var a = Number(this.getField("Q1").value); // rate;

var b = Number(this.getField("Q1Int").value); // nper;

var c = Number(this.getField("Q1Yr").value); // pmt;

var d = Number(this.getField("Q1Pmt").value); // pv;

var e = 1; // type?

event.value = FV(a, b, c, d, e);

You have not provided any information about the "type" parameter.

From your image I see you have 2 fields with the name "Q2Int" and not one field named "Q1Int". This will generate an error when you try to compute the future value for line one because you have no field named "Q1Int". This error should appear in the Acrobat JavaScript Console if you have it open to set to open upon an error.

TOPICS

Acrobat SDK and JavaScript,
Macintosh,
Windows

Community Guidelines

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

Jul 23, 2017

Copy link to clipboard

Copied

You are not passing the values for the parameters of the function in the function call. It looks like you are also trying to define the function when you are setting the events. value.

I would create a document level script named "FV" and place the following code into script.

function FV(rate, nper, pmt, pv, type) {

var pow = Math.pow(1 + rate, nper), fv;

if (rate) {

fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow;

} else {

fv = -1 * (pv + pmt * nper);

}

return fv.toFixed(2);

}

For the field calculation I would use the following code:

var a = Number(this.getField("Q1").value); // rate;

var b = Number(this.getField("Q1Int").value); // nper;

var c = Number(this.getField("Q1Yr").value); // pmt;

var d = Number(this.getField("Q1Pmt").value); // pv;

var e = 1; // type?

event.value = FV(a, b, c, d, e);

You have not provided any information about the "type" parameter.

From your image I see you have 2 fields with the name "Q2Int" and not one field named "Q1Int". This will generate an error when you try to compute the future value for line one because you have no field named "Q1Int". This error should appear in the Acrobat JavaScript Console if you have it open to set to open upon an error.

TOPICS

Acrobat SDK and JavaScript,
Macintosh,
Windows

Community Guidelines

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

dennisb777

Jul 23, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/td-p/9226529
27
Replies
27

Jul 23, 2017

Copy link to clipboard

Copied

Community Guidelines

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

Reply

Loading...

Karl Heinz Kremer

Jul 23, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226530#M30231
Jul 24, 2017

Copy link to clipboard

Copied

Thank you Karl for your valiant effort to help me, but unfortunately, you are dealing with someone illiterate in Java. I was actually astute enough to do the same search and found the same formula, but after several attempts, I can’t seem to modify the variables to work in my form. Plus, I don’t know what the “type” variable has to do with anything. In addition, I don’t need the “payment” variable, but can input a field for it. I have included an attachment so you can see what I am working with if you have the desire to help once again.

Thank you in advance for your consideration and time.

Community Guidelines

Reply

Loading...

dennisb777

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226531#M30232
Jul 24, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

try67

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226532#M30233
Jul 24, 2017

Copy link to clipboard

Copied

Let me start with this: Do yourself a favor and learn how JavaScript works. You cannot copy and paste your way to a successful solution if you don't know what you are doing. You need to be able to adapt what you find here (and in other places) to your specific requirements, and fix potential problems when the requirements change in the future. Here is some information about how to learn to program in JavaScript for Acrobat: http://khkonsulting.com/2017/01/learning-to-program-javascript-for-adobe-acrobat/

Also, you are not dealign with "Java", this is "JavaScript" - similar name, but completely different environment, and very important when you try to search for solutions. You will not be able to adapt a Java solution to work within Acrobat at all. You can however adapt a JavaScript solution (as long as it's only using the core language) - usually without too many problems.

Here are a few pointers to how you can make this work:

To get the value of a field, you would use this syntax:

var someValue = this.getField("SomeFieldName").value;

To set the current field value in a custom calculation script, you would use this:

event.value = someValue;

This, plus the scripts you've found, plus a good working knowledge of how JavaScript works should be all you need.

Community Guidelines

Reply

Loading...

Karl Heinz Kremer

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226533#M30234
Jul 24, 2017

Copy link to clipboard

Copied

I have a very basic understanding, and have written the formulas for a hundred other basic calcs in the form; but this FV is kicking my rear...therefore, I will spend some more time in the link you gave to me...thank you. Here is my latest attempt to adapt the script to my form fields, but it doesn't work. I am sure part of the problem is that I don't have variables for pmt or type. I don't even know what "type" is to the equation. I don't need "pmt" so I tried removing both of them, but that didn't work either. I am sorry to be so much trouble. Thank you for any help you can provide.

var a = Number(this.getField("Q1").value);

var b = Number(this.getField("Q1Int").value);

var c = Number(this.getField("Q1Yr").value);

var d = Number(this.getField("Q1Pmt").value);

event.value = function FV(rate, nper, pmt, pv, type) {

var pow = Math.pow(1 + rate, nper),

fv;

if (rate) {

fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow;

} else {

fv = -1 * (pv + pmt * nper);

}

return fv.toFixed(2);

}

Community Guidelines

Reply

Loading...

dennisb777

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226534#M30235
Jul 24, 2017

Copy link to clipboard

Copied

Here is another recent attempt, but it did not work either:

var a = Number(this.getField("Q1").value);

var b = Number(this.getField("Q1Int").value);

var c = Number(this.getField("Q1Yr").value);

var d = Number(this.getField("Q1Pmt").value);

function FV(a, b, c, d) {

var pow = Math.pow(1 + b, c),

fv;

if (b) {

fv = (d*(1+b)*(1-pow)/b)-a*pow;

} else {

fv = -1 * (a + d * c);

}

return fv.toFixed(2);

Community Guidelines

Reply

Loading...

dennisb777

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226535#M30236
Jul 24, 2017

Copy link to clipboard

Copied

Where do you use the function FV?

Community Guidelines

Reply

Loading...

Bernd Alheit

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226536#M30237
Jul 24, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

dennisb777

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226537#M30238
Jul 24, 2017

Copy link to clipboard

Copied

I miss following in your code:

event.value = FV(a, b, c, d);

Community Guidelines

Reply

Loading...

Bernd Alheit

Jul 24, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226538#M30239
Jul 25, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

dennisb777

Jul 25, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226539#M30240
Jul 25, 2017

Copy link to clipboard

Copied

Why did you remove the function definition?

function FV(a, b, c, d) {

Community Guidelines

Reply

Loading...

Bernd Alheit

Jul 25, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226540#M30241
Jul 25, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

dennisb777

Jul 25, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226541#M30242
Jul 25, 2017

Copy link to clipboard

Copied

Here is the original formula I was given and told would work, can you please tell me what "type" is; and help me modify this formula into a working javascript for my working form?

`function FV(rate, nper, pmt, pv, type) { var pow = Math.pow(1 + rate, nper), fv; if (rate) { fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow; } else { fv = -1 * (pv + pmt * nper); } return fv.toFixed(2); }`

` `

` `

` `

Community Guidelines

Reply

Loading...

dennisb777

Jul 25, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226542#M30243
Jul 25, 2017

Copy link to clipboard

Copied

At the end you must add the code of the 9. reply.

Community Guidelines

Reply

Loading...

Bernd Alheit

Jul 25, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226543#M30244
Jul 26, 2017

Copy link to clipboard

Copied

First, I want to once again thank you Mr. Alheit for continuing to try and help me, however I do not understand what the "code of the 9" is; much less how to add it at the end. When I consider the other working formulas in this adobe form, most of them end with some variation of this: "event.value =((a+b+c)-d);"

Is this what you are referring to or is it something different. Once again, here is the formula I was given.

`function FV(rate, nper, pmt, pv, type) {`

var pow = Math.pow(1 + rate, nper),

fv;

if (rate) {

fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow;

} else {

fv = -1 * (pv + pmt * nper);

}

return fv.toFixed(2);

}

Can you please type in what to add at the end -- and show me the proper syntax? Thank you so much!

Community Guidelines

Reply

Loading...

dennisb777

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226544#M30245
Jul 26, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

try67

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226545#M30246
Jul 26, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

dennisb777

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226546#M30247
Jul 26, 2017

Copy link to clipboard

Copied

Use this:

var a = Number(this.getField("Q1").value);

var b = Number(this.getField("Q1Int").value);

var c = Number(this.getField("Q1Yr").value);

var d = Number(this.getField("Q1Pmt").value);

function FV(a, b, c, d) {

var pow = Math.pow(1 + b, c),

fv;

if (b) {

fv = (d*(1+b)*(1-pow)/b)-a*pow;

} else {

fv = -1 * (a + d * c);

}

return fv.toFixed(2);

}

event.value = FV(a, b, c, d);

You should learn the basics of JavaScript.

Community Guidelines

Reply

Loading...

Bernd Alheit

Jul 26, 2017
2
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226547#M30248
Jul 26, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

try67

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226548#M30249
Jul 26, 2017

Copy link to clipboard

Copied

Thank you again Mr. Alheit, you have been patient and generous with me. Apparently, everyone is becoming frustrated with me and I am sorry. I have been, and I am still am reading and trying to learn the basics, that is how I have created this 3 page spreadsheet with dozens of its working formulas up to this point. I was just asking for help on this one more complex formula (FV).

By the way, THANK YOU again for your attempt to send me a working formula, that is more than anyone else has done, but it does not work either...no errors, just no results calculated. I will try not to bother you or anyone else again...I don't want any hard feelings. I am simply a financial advisor trying to create a spreadsheet to help my clients. Have a blessed day!

Community Guidelines

Reply

Loading...

dennisb777

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226549#M30250
Jul 26, 2017

Copy link to clipboard

Copied

I can tell you in this snippet:

`function FV(rate, nper, pmt, pv, type) {`

var pow = ...

` ... lines as in earlier post ...`

return fv.toFixed(2);

}

that "type" does nothing. It has no special meaning, and does not appear. So it can be anything. However, it must be there with some value or other when you call it. Why is it there? You'd have to ask the author. Perhaps they meant it to do something, or planned to do so in the future, were distracted, or it's a house style, or for debugging.

You may not welcome this insight, but it may be useful: I never, ever, post snippets of code, no matter how useful. Because it leads people into exactly such traps as this, if they are trying to program without fully understanding. I call this "copy and paste programming" and as a programming professional I will sometimes use it, but I have to do so with the utmost care. I know exactly why you'd be looking for a shortcut to save the months of study, but it is a dangerous path: just as you would hardly approve of someone trying to go out as a financial adviser who is untrained, but listens then does Google searches. This is important if you are creating or using a formula which will form the basis of financial advice: who will be responsible if it is wrong?

Community Guidelines

Reply

Loading...

Test Screen Name

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226550#M30251
Jul 26, 2017

Copy link to clipboard

Copied

I totally agree about the dangers of programming by copying-and-pasting. However, "type" *is* used in the function (at least in one of the versions above), in this line:

`fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow;`

Community Guidelines

Reply

Loading...

try67

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226551#M30252
Jul 26, 2017

Copy link to clipboard

Copied

Let me repeat what I said very early in this discussion:

You cannot copy and paste your way to a successful solution if you don't know what you are doing.

There are two ways you can get to a working, reliable and maintainable solution:

1) You do the research and learn enough about the problem and the programming environment to be able to take a code snippet you find online and massage it into something that works in your environment.

2) You pay somebody to do the task for you and potentially provide the training along the way so that next time, you can make adjustments to the final product.

You need to go back to where you found this code snippet (the Stack Overflow link from the beginning of this discussion). There you will see that this JavaScript function is a functional equivalent of the Excel function with the same name. You can find out what exactly it does here: FV function - Office Support

You will see that the "type" argument is optional in Excel. Unfortunately, the JavaScript function insists on this parameter being there, so you can always pass in "0" or "1" (meaning the payment is due at beginning or end of period - see the documentation). If you only ever need one of these cases, then the function can be simplified so that "type" is no longer used, but that again requires you to know what you are doing.

The Excel function "FV" may not be exactly what you need in your application - we don't know that because we don't know how exactly your form will work, so that again is something where you need to be able to adjust the functionality in this given function to match your specific needs.

I can tell you that the function provides the same results that are shown in the documentation page that I linked to. Here is even a simple PDF form that shows that: http://khkonsulting.com/files/AUC/FV.pdf

Community Guidelines

Reply

Loading...

Karl Heinz Kremer

Jul 26, 2017
2
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226553#M30254
Jul 26, 2017

Copy link to clipboard

Copied

You are not passing the values for the parameters of the function in the function call. It looks like you are also trying to define the function when you are setting the events. value.

I would create a document level script named "FV" and place the following code into script.

function FV(rate, nper, pmt, pv, type) {

var pow = Math.pow(1 + rate, nper), fv;

if (rate) {

fv = (pmt*(1+rate*type)*(1-pow)/rate)-pv*pow;

} else {

fv = -1 * (pv + pmt * nper);

}

return fv.toFixed(2);

}

For the field calculation I would use the following code:

var a = Number(this.getField("Q1").value); // rate;

var b = Number(this.getField("Q1Int").value); // nper;

var c = Number(this.getField("Q1Yr").value); // pmt;

var d = Number(this.getField("Q1Pmt").value); // pv;

var e = 1; // type?

event.value = FV(a, b, c, d, e);

You have not provided any information about the "type" parameter.

From your image I see you have 2 fields with the name "Q2Int" and not one field named "Q1Int". This will generate an error when you try to compute the future value for line one because you have no field named "Q1Int". This error should appear in the Acrobat JavaScript Console if you have it open to set to open upon an error.

Community Guidelines

Reply

Loading...

gkaiseril

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226554#M30257
Jul 26, 2017

Copy link to clipboard

Copied

Mr. Gkaiseril

THANK YOU for the time you have taken to help me to help others!

THANK YOU for your kindness!

THANK YOU SIR for being so considerate!

You are a programming wizard and your answer worked perfectly--solving a riddle others could not or would not!

May the Lord richly bless you!

Community Guidelines

Reply

Loading...

dennisb777

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226555#M30258
dennisb777
LATEST

Jul 26, 2017

Copy link to clipboard

Copied

Thank you as well Karl, your answers set me on the correct path.

Community Guidelines

Reply

Loading...

dennisb777

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226556#M30261
Jul 26, 2017

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

Test Screen Name

Jul 26, 2017
0
/t5/acrobat-sdk/how-to-calculate-quot-future-value-quot-of-an-investment/m-p/9226552#M30253
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.