Skip to main content
Participant
September 27, 2021
Answered

Stopping subtraction calculations going past 0

  • September 27, 2021
  • 1 reply
  • 462 views

I am designing a PDF form for assessments. Basically there is one section that when ticked will give them full marks, this is displayed in a text box called "AOTRVSS". There are multiple selections that can be ticked for deductions in marks from errors. The total of this is displayed in "AOTRVSD".

I have a separate box to calculate the total of that section. The calculcation I am using in here is AOTRVSS-AOTRVSD 

However, from research I cannot work out how to stop it going into a negative number and staying at 0. Basically there are more marks for errors that can be taken off compared to the amount allocated for that section. If the person being assessed completed the section (and got 2 for doing so) but made 6 errors that are all assigned a value of 0.5 (and got 3 marks deducted) I want the calculation to stop at 0 not go to -1 when calculating the total.

I have tried numerous complex calculations from looking at what others have done but to no avail. Any help in this field would be greatly appreciated. 

This topic has been closed for replies.
Correct answer Nesa Nurani

try something like this as custom calculation script:

var a = Number(this.getField("AOTRVSS").value);
var b = Number(this.getField("AOTRVSD").value);
var x = a-b;
if(x<0) event.value = 0;
else event.value = x;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 27, 2021

try something like this as custom calculation script:

var a = Number(this.getField("AOTRVSS").value);
var b = Number(this.getField("AOTRVSD").value);
var x = a-b;
if(x<0) event.value = 0;
else event.value = x;

KirstyMAuthor
Participant
September 27, 2021

That worked!! Thank you so much! I really appreciate your help!