Skip to main content
Participating Frequently
July 23, 2017
해결됨

How to calculate "Future Value" of an investment?

  • July 23, 2017
  • 2 답변들
  • 4996 조회

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

이 주제는 답변이 닫혔습니다.
최고의 답변: gkaiseril

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);

}


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.

2 답변

Legend
July 26, 2017

Hmm, I did a text search to double check but I may have got it wrong. Seems in this case doubly important to find the author's intention.

Karl Heinz  Kremer
Community Expert
Community Expert
July 23, 2017

This actually has nothing to do with Acrobat's implementation of JavaScript: The advantage of using JavaScript as a programming language inside Acrobat is that you can use any JavaScript function that does only use core JavaScript language features in your script in Acrobat. This means that you can google for e.g. "future value investment javascript" and find solutions that will work for you (e.g. here: excel - How to calculate Future Value (FV) using JavaScript - Stack Overflow​)

dennisb777작성자
Participating Frequently
July 24, 2017

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.

Bernd Alheit
Community Expert
Community Expert
July 24, 2017

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);


Where do you use the function FV?