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

Simple Calculation Script

Community Beginner ,
Jul 24, 2024 Jul 24, 2024

Copied

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!

TOPICS
General troubleshooting , JavaScript , PDF forms

Views

138

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 Expert , Jul 24, 2024 Jul 24, 2024

- 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.

6 Replies 6
Community Expert ,
Jul 24, 2024 Jul 24, 2024

Copied

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.

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 Beginner ,
Jul 24, 2024 Jul 24, 2024

Copied

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.

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 Expert ,
Jul 24, 2024 Jul 24, 2024

Copied

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

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 Beginner ,
Jul 24, 2024 Jul 24, 2024

Copied

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

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 Expert ,
Jul 24, 2024 Jul 24, 2024

Copied

- 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.

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 Beginner ,
Jul 24, 2024 Jul 24, 2024

Copied

LATEST

That worked! Thank you!