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

How to calculate a division

New Here ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

I need to do a division as calculation and I don't know how to do it. I don't know where to find the answer. If nobody answer my question I will probably use another software than Adobe DC. i cannot find my answer on Adobe site. Really bad done

TOPICS
Create PDFs

Views

3.0K

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
LEGEND ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

Assuming you're working with a form, you'll have to use JavaScript. Here's a sample custom calculate script for a text field:

// Custom calculate script

// Get the field values, as numbers

var numerator = +getField("text1").value;

var denominator = +getField("text2").value;

// Calculate and set this field value

if (denominator !== 0) {

    event.value = numerator / denominator;

} else {

    event.value = "";

}

You'd have to replace "text1" and "text2" with the actual field names, and perhaps modify this script if you're doing something other than dividing one field value by another.

Also, that last if/else block can be reduced to just the following"

// Calculate and set this field value

event.value = denominator !== 0 ? numerator / denominator : "";

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
New Here ,
Sep 26, 2023 Sep 26, 2023

Copy link to clipboard

Copied

Hi - thank you for the above; can you tell me how I can get it to check if another drop-down field = Yes, then run the division calculation.  Otherwise, leave value (%) at 0.

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 ,
Sep 27, 2023 Sep 27, 2023

Copy link to clipboard

Copied

Change:

if (denominator !== 0) {

To:

if (denominator !== 0 && this.getField("Dropdown1").valueAsString=="Yes") {

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
New Here ,
Sep 28, 2023 Sep 28, 2023

Copy link to clipboard

Copied

Thank you! I really appreciate the help. Can you please confirm if I have
this interpreted/inserted correctly?

// Custom calculate script

// Get the field values, as numbers

var numerator = this.getField("Field Name").value;

var denominator = this.getField("Field Name").value;

// Calculate and set this field value

if (denominator !== 0 && this.getField("Dropdown1").valueAsString=="Yes")

{event.value = denominator !== 0 ? numerator / denominator : "";}

else {event.value = "";}


Have a super day!

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 ,
Sep 28, 2023 Sep 28, 2023

Copy link to clipboard

Copied

Yes, but you have to replace "Field Name" and "Dropdown1" with the actual names of the fields in your file...

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
New Here ,
Sep 28, 2023 Sep 28, 2023

Copy link to clipboard

Copied

LATEST
Perfect - thank you!!

I will be adding the script into the document today.

Have a super day!

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
New Here ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

When I write the code you gave me it does not work. When I write 'this.getField' instead of +getField it works. Why?

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 ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

The "this" keyword can sometimes be dropped when it is applied from the context, but I don't like this habit and recommend to always use it. Others disagree.

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
LEGEND ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

Where exactly did you place the code?

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