Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Zero if negative number

Avatar

Level 4

I am trying to get a form to show a zero if the number subtracted results in a negative.

ie $100 - $200 = $0

Please help the scripting afflicted.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

The script in the calculate event of the numeric field would need an if/else statement. For example (using JavaScript):

var nAns = NumericField1.rawValue - NumericField2.rawValue;

if (nAns >= 0) {

     this.rawValue = nAns;

}

else {

     this.rawValue = 0;

}

Hope that helps,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

The script in the calculate event of the numeric field would need an if/else statement. For example (using JavaScript):

var nAns = NumericField1.rawValue - NumericField2.rawValue;

if (nAns >= 0) {

     this.rawValue = nAns;

}

else {

     this.rawValue = 0;

}

Hope that helps,

Niall

Avatar

Level 4

Correct as always. Thanks, Niall.

I have little scraps of paper with your scripts on them taped all over the walls of my office. They always did think I was strange here.

Your friend, Cake Diva

Avatar

Level 10

...I'll just have to turn those scraps into a book!