Skip to main content
Participant
April 12, 2021
Answered

Only Add Negative Numbers

  • April 12, 2021
  • 1 reply
  • 1183 views

Hello ladies and gentlefolks!

 

I have a form in which a section of it utilizes numbers - both negative and positive numbers. The options are set to change negative numbers to be red and in parenthesis. I also created an additional field - but what I need for it to do is to only take the numbers that are of a negative value and add only those negative values together (ignoring thje positive or zeros) to give me a grand (negative) total. I use Acrobat Pro DC (not sure if this all of the information that is needed).

 

Thank you so much in advance.

This topic has been closed for replies.
Correct answer try67

You can use this code as the custom calculation script of the field that should display the total owed amount:

 

var total = 0;
for (var i=1; i<=16; i++) {
	var v = Number(this.getField("R"+i+"B").valueAsString);
	if (v<0) total+=v;
}
event.value = total;

1 reply

T_DruryAuthor
Participant
April 12, 2021

I guess I could have attached a screenshot....  Here is more of what I am trying to do...

 

All of the fields labeled as "RxB" will have the numbers in the (either a positive or a negative)

The "Total Owed" field should only be calculating all of the negative numbers from the "RxB" fields.

 

I hope this clarifies and that my attachment uploaded correct (new MacBook)

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 12, 2021

You can use this code as the custom calculation script of the field that should display the total owed amount:

 

var total = 0;
for (var i=1; i<=16; i++) {
	var v = Number(this.getField("R"+i+"B").valueAsString);
	if (v<0) total+=v;
}
event.value = total;