Skip to main content
Known Participant
February 18, 2020
Answered

Using the Absolute Function

  • February 18, 2020
  • 1 reply
  • 2012 views

Hi All Ive got the following script working to give me the difference between two fields, but would like the answer to always appear as a positive number i.e. the absolute number even if the result is negative.

 

event.value =this.getField("BOW").value - this.getField("Ahead_Mark").value;

 

Im just not sure how to put the Maths.abs function or if this is even the right function to use.

 

Thanks in advance.

This topic has been closed for replies.
Correct answer Bernd Alheit

Use this:

event.value = Math.abs(Number(this.getField("BOW").valueAsString) - Number(this.getField("Ahead_Mark").valueAsString));

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
February 18, 2020

Use this:

event.value = Math.abs(Number(this.getField("BOW").valueAsString) - Number(this.getField("Ahead_Mark").valueAsString));
Known Participant
February 18, 2020

Perfect - thank you for your help.

 

cheers

LC