Skip to main content
jean-françoisj97325759
Known Participant
July 9, 2018
Question

How to calculate a division

  • July 9, 2018
  • 2 replies
  • 4634 views

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

This topic has been closed for replies.

2 replies

jean-françoisj97325759
Known Participant
August 15, 2018

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

try67
Community Expert
Community Expert
August 15, 2018

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.

Inspiring
July 9, 2018

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 : "";

Participant
September 26, 2023

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.

try67
Community Expert
Community Expert
September 27, 2023

Change:

if (denominator !== 0) {

To:

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