Skip to main content
Participant
November 20, 2024
Question

Calculation in editable form

  • November 20, 2024
  • 2 replies
  • 195 views

I would like to create a calculation in an editable form (Field A - Field B / Field C) but I would like the field to populate in percentage up to 2 decimal places. I tried entering in the simplified field notation Field A-Field B/Field C*100 but it does not work

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
November 20, 2024

Since your calculation involves division, the Simplified Field Notation (SFN) is not recommended. A custom calculation script is a better solution because "FIELD C" might be empty or 0, which would cause a division error. Here's a recommended script:

var a = Number(this.getField("FIELD A").valueAsString);
var b = Number(this.getField("FIELD B").valueAsString);
var c = Number(this.getField("FIELD C").valueAsString);

if(c != 0){
 event.value = (a-b)/c;}
else
 event.value = 0;

Ensure you are using the right formula:

a - b / c divides b by c first, then subtracts the result from a.
If you intended for (a - b) to be divided by c, enclose it in parentheses: (a - b) / c.

 

Format the field as a percentage with 2 decimal places:

Right-click the calculation field and select Properties.
Go to the Format tab.
Choose Percentage and set Decimal Places to 2.

 

PDF Automation Station
Community Expert
Community Expert
November 20, 2024

You can't have spaces in field names in a simplified field notation without escaping the spaces.  Try this:

Field\ A-Field\ B/Field\ C

Or you can do a custom calculation script instead like this:

event.value=this.getField("Field A").value - this.getField("Field B").value/this.getField("Field C").value;

Format the field to percentage with 2 decimal places.