Skip to main content
Patrick at Ebins
Participant
January 12, 2019
Question

Java Subtraction for Positive # only

  • January 12, 2019
  • 1 reply
  • 305 views

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

This topic has been closed for replies.

1 reply

Inspiring
January 12, 2019

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;

})();