Java Subtraction for Positive # only

Jan 11, 2019

Copy link to clipboard

Copied

I am trying to add two fields for a sum in a third field, but only if the 2nd field is a positive number. The two fields I am adding are: “Total Hotel Expenses” and “Total ASP Less Per Diem” to come up with a total in the field “Total Expenses Due”. But if the “Total ASP Less Per Diem” is a negative number then I want it to add it as 0. Any assistance would be greatly appreciated…Thanks Patrick

TOPICS
Acrobat SDK and JavaScript, Windows

Views

57

Likes

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

Java Subtraction for Positive # only

Jan 11, 2019

Copy link to clipboard

Copied

I am trying to add two fields for a sum in a third field, but only if the 2nd field is a positive number. The two fields I am adding are: “Total Hotel Expenses” and “Total ASP Less Per Diem” to come up with a total in the field “Total Expenses Due”. But if the “Total ASP Less Per Diem” is a negative number then I want it to add it as 0. Any assistance would be greatly appreciated…Thanks Patrick

TOPICS
Acrobat SDK and JavaScript, Windows

Views

58

Likes

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
Jan 11, 2019 0
Jan 11, 2019

Copy link to clipboard

Copied

You could do something like this as the custom calculation script for the Total Expenses Due field:

// Custom calculation script

(function () {

    // Get the input field values, as numbers

    var v1 = +getField("Total Hotel Expenses").value;

    var v2 = +getField("Total ASP Less Per Diem").value;

   if (v2 < 0) v2 = 0;

    // Set this field's value to the sum

    event.value = v1 + v2;

})();

Likes

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
Reply
Loading...
Jan 11, 2019 0