Skip to main content
Participant
July 24, 2024
Answered

Simple Calculation Script

  • July 24, 2024
  • 1 reply
  • 1233 views

Hi! I'm pretty new to the idea of making calculation scripts in Adobe Acrobat, just to preface.

 

I'm trying to calculate the Time Value of Money and when I do the calculation with only the numbers it works out perfectly but as soon as I plug in my variables that equal those numbers my calculation no longer gives me the number it's supposed to. Here's the script I'm working with as a Simplified Field Notation.

 

c2 * ( 1 + 0.05 / 1 ) ^ 67 - Nn + a1 * c1 /0.05 ( ( 1 + 0.05 / 1 ) ^ 67 - Nn -1) * 1 

 

Nn = 30

a1 = 50,000

c1 = 10%

c2 = 1,000

 

I appreciate any help, thanks!

This topic has been closed for replies.
Correct answer try67

Thank you. I've been working on it a bit more and this is what I have. It's still not coming up with any numbers.

 

var Cc = Number(this.getField("Cc")); console.println("Cc "+ Cc); var Ca = Number(this.getField("Ca")); var a1 = Number(this.getField("a1")); var Nn = Number(this.getField("Nn")); var first_pwr = Math.pow( event.value = Math.pow((Ca * ( 1 + 0.05 / 1 ) , ( 67 - Nn ) + ( a1 * Cc ) / 0.05 * ( ( 1 + 0.05 / 1 ) ,( 67 - Nn ) - 1 ) * 1 ));


- You forget the .valueAsString part in the definitions of the variables.

- Not sure why you stuck event.value in the middle of the last line. It needs to be at the start of it.

- Since your formula is a bit complex I would recommend splitting it into parts. Each part can be defined as a variable and then use later on in the final calculation.

1 reply

try67
Community Expert
Community Expert
July 24, 2024

You can't use the Simplified Field Notation if you need to use the Power operator. You must use a script.
And the way to do that in JS is with this command:

Math.pow(x,y)

This will return x^y.

Also, you need to make sure that the value of your percentage field is not 10 but 0.1, for the calculation to work correctly.

Reilly.HAuthor
Participant
July 24, 2024

Thank you so much. Does my calculation have to change much to convert into Javascript? I have not worked in Javacsript before, only HTML and css.

try67
Community Expert
Community Expert
July 24, 2024

Not much... You just need to define the variables, and use the correct operators (except for Power they are all the same as in the Simple Notation), and apply the result to event.value at the end.

Here's a simple example:

 

var A = Number(this.getField("A").valueAsString);

var B = Number(this.getField("B").valueAsString);

event.value = Math.pow((A * B) / 400, 2);

 

This is the same as: ((A * B) / 400) ^ 2

 

See here for some more info: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations