Skip to main content
Participant
December 9, 2016
Question

Negative number after calculation showing 0

  • December 9, 2016
  • 1 reply
  • 324 views

I am creating an inventory form that has columns of Par, QOH and Amount to Order

Field Names

P1 | Q1 | O1

___________

P1 - Q1 = O1

Par # - Quantity on Hand # = Amount to order

Example:

If par is set at 6 and QOH is 4 we need to order 2. [6-4=2]

BUT, if par is set at 6 and QOH is 8 we do not need to place an order but the output is negative (-2). [6-8=(2)]

How do I make the output show zero when the calculation shows a negative answer?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
December 9, 2016

As the custom calculation script of O1 use this code:

var p1 = Number(this.getField("P1").valueAsString);

var q1 = Number(this.getField("Q1").valueAsString);

event.value = Math.max(0, p1-q1);

Edit: Fixed a type-o in the code...