Quantcast
Channel: Adobe Community : Popular Discussions - JavaScript
Viewing all articles
Browse latest Browse all 12130

Showing negative numbers as 0

$
0
0

Box 1: User Input

Box 2: User Input

Box 3: User Input

Box 4: User Input

Box 5: (Box 1 - Box 2)

Box 6: (Box 3 + Box 4)

Box 7: (Box 5 - Box 6)

 

So I'm using the following equation for Boxes 5, 6 & 7:

 

var v1 = getField("Box #").valueAsString;

var v2 = getField("Box #").valueAsString;

 

     if (v1 && v2) {

        // Perform the calculation

        event.value = +v1 - +v2;

     } else {

         event.value = "";

     }

 

 

**Note for box 6, the in the calculation is replaced with (+).

------------------------------------------------------------------------------------------ --------------

 

My question: How do I write this code to produce/show "0" if the equation results in a negative number?


Viewing all articles
Browse latest Browse all 12130

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>