Showing negative numbers as 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?

You need another "if" statement or you use a logical value to multiply the result of the calculation by 1 if not negative or by 0 if negative. The logical true and false have a numerical value. True is 1 and false is 0,
var v1 = this.getField("Box #").valueAsString;
var v2 = this.getField("Box #").valueAsString;
event.value = "";
      if (v1 && v2) {
        // Perform the calculation
        if((v1 - 2) >= 0)  event.value = (v1 - 2) * ((v1 - 2) >= 0); // display result for non-negative values;
        else event.value = 0; // display 0 for negative values;
or:
var v1 = this.getField("Box #").valueAsString;
var v2 = this.getField("Box #").valueAsString;
event.value = "";
if (v1 && v2) {
       // Perform the calculation;
     // display result if not negative or 0;
        event.value = (v1 - 2) * ((v1 - 2) > 0);
Since the calculation is repeated with only a change in the field names, I would consider using a function that takes the field names as parameters and returns the result of the calculation.
// document level or page open function;
function PosativeResult(cField1, cField2, cOper) {
var v1 = this.getField(cField1).valueAsString;
var v2 = this.getField(cField2).valueAsString;
if(typeof cOper == "undefined") cOper = "+";
var nResult = "";
if (v1 && v2) {
       // Perform the calculation;
        nResult = eval(Number(v1) + " " + cOper + " " + Number(v2))
          // display only positive results or zero;
        nResult *= (nResult > 0);
return nResult;
} // end PosaiveResult function;
// custom calculation for Box5;
event.value = PosativeResult("Box1", "Box2", "-");
// custom calculation for Box6;'
event.value = PosativeResult("Box3", "Box4", "+");
// custom calculation for Box7;
event.value = PosativeResult("Box5", "Box6", "-");
Are you sure you provided the correct equations for the field values?
Changing the operator make the script more complex.

Similar Messages

  • Is anyone having trouble using parenthesis to show negative numbers in excel after upgrading to Yosemite?

    Since upgrading to Yosemite, I can no longer reflect negative numbers with parenthesis using excel.  All of my existing spreadsheets also no longer show parenthesis, creating formatting problems.  Is anyone else experiencing this and is there a solution?

    I suggest you post your question to Microsofts own forums for their Mac software as it's their product you're having issues with
    http://answers.microsoft.com/en-us/mac

  • Can anyone tell me how to Format cell values in numbers? I am wanting to make any negative numbers in brackets.

    Anyone able to help?

    You might want to post questions like this over on the Numbers community since it's more likely you'll find expertise there.
    However, this one I can help with.  If not already showing, you need to turn on the Inspector in Numbers.  You do that by clicking on the Inspector icon in the upper right, showing the inspector box highlighted in red below:
    Now select the cell(s) you want to format and click on the fourth tab (the one with the "42" in a box).  If want no currency sign, select number as your format, while if you want a currency symbol select currency as the format.
    Next to the "Decimals" option is the box in which you can select your "negative" format--you have four options for showing negative numbers, two of which will place negative numbers in parenthesis.
    Note that the inspector box controls a number of options and settings in Numbers. 
    If you used to working with Excel you have to understand that Numbers works entirely differently and will have more than a bit of a learning curve. 
    Generally I find Numbers is the weakest of the iWork offerings.  It is a useful program if you need a heaviliy formatted presentation of pure spreadsheet data, though if you want formatted spreadsheets in a mainly text report the Word/Excel combination works better.
    The program also falls short in a number of areas vs. Excel if your spreadsheet needs go beyond the basic.  It certainly isn't the most efficent at dealing with a large spreadsheet (and, in fact, the fact the default templates all have only a few rows is a good hint that this might not be the product for that megasheet :-) ).
    But if you just have basic spreadsheet needs it certainly can do the job.

  • How can I get rid of negative numbers that is showing as my wifi icon

    My iphone 4 is jail broken . randomly now my wifi icon is showing negative numbers

    This may not have been done by jailbreaking, you can also do this from field mode which is perfectly legit from Apple's point of view.
    Dial *3001#12345#*
    1. Your iPhone is now in the Field Test mode. Do you see a signal strength value on the upper left hand corner? You can still switch to the old strength bars instead of the number value, by taping on it.  You can revert to the bars any time by closing the app by pressing the home button. If you want to have the number indicator permanently (which is again reversible to bars), proceed to step 2.
    2. Hold on to the power button until you see the bar that says ‘slide to power off’. Here, do NOT power off your iPhone.
    3. Now press the home button again until the app is exited and you’re on to the home screen.
    4. To revert to the original signal strength representation, dial *3001#12345#* and press ‘Call’ to enter the field test mode again. Then press the home button once.

  • Why are SPAM messages showing hits=negative numbers and getting through?

    Message headers in known SPAM are reporting NEGATIVE numbers!
    How do I figure out what rule is pushing them into the negative?
    No wonder SPAMASSASSIN isn't catching much.
    ===========================================
    Here are headers of two SPAM messages:
    X-Spam-Status: No, hits=-4.102 tagged_above=-999 required=3
    tests=ALL_TRUSTED,
    AWL, BAYES_00, HTML90100, HTMLIMAGE_RATIO06, HTML_MESSAGE
    X-Spam-Level:
    ==============================================
    X-Spam-Status: No, hits=-3.283 tagged_above=-999 required=3
    tests=ALL_TRUSTED,
    BAYES_00, HTML90100, HTMLBADTAG_0010, HTMLIMAGE_RATIO02,
    HTML_MESSAGE,
    HTMLTAG_EXISTTBODY
    X-Spam-Level:
    ===============
    Does that mean that one or more of the tests shown above has to be the culprit?
    Thanks,
    Keith

    This is the test you do not want to trigger for external mail: ALL_TRUSTED
    Chances are you are using NAT. For a solution see here:
    http://wiki.apache.org/spamassassin/TrustPath
    HTH,
    Alex

  • Show negative values as 0 in BEx Report

    Hi Gurus,
    I have a report which shows negative values for POs in BW BEx. The user wants all negative values to show up as 0 in the report. Is there a way I can show that as 0 in the report  for all negative numbers easily.
    Any help is deeply appreciated.
    Thanks.

    Hi,
    Make a new formula and write a simple condition like this.
    (PO value<=0)*0+(PO value>0)*PO value
    Make sure to use boolean operators while writing this condition.If any issues get back to me.
    Hope it helps.
    Regards,
    AL

  • Negative numbers in export to excel

    Hi,
    We have two servers, one (X) without SP1 and the other (Y) with SP1.
    When I make export to excel in X, the negative numbers sometimes saved as @ or the actual negative number (e.g. -42), in both cases it is saved as text.
    The positive numbers are saved as numbers.
    We saw that SAP fixed it in SP1, we tried it on Y, we got that the negative numbers always show (e.g. -42), but all the numbers, positive and negative are saved as text.
    We need to see all the actual numbers(without @), and to be saved as numbers (so we can make calculations on them).
    Does anyone have any idea?
    Thanks.

    I am on SP1 and noticed that sometimes they are saved as numbers and some are texts:
    So I am not sure of any logic or what is going on.
    Maybe as a work around you could format everything to numbers so you can do the calculation?

  • Negative Numbers importing wrong

    I have a Stored Procedure on my SQL Server 6.5 DB that returns a list of decimal values (sql datatype is decimal(5,2)), of which most are Negative numbers. When the procedure is run in a SQL tool (MS Query or ISQL) the values are returned correctly. When the stored procedure is called in Java, all values (negative or positive) are showing up as zero.
    I have tried all of the following ...
    double d = rs.getDouble(1);
    Float f = rs.getFloat(1);
    Double d2 = new Double(rs.getDouble(1));
    BigDecimal b = rs.getBigDecimal(1);
    String s = rs.getString(1);The value returned by the procedure should look something like -14.75 but when using System.out.println(f.toString()); it is shown as ".00". I have even tried exporting the data out of Java into MS Excel to see if it is just something funny with the System.out.println() statement but it shows all zeros in Excel also.
    Is there anything special or a specific data type that must be used for negative numbers to read correctly in Java? I've searched the forum, tutorials and API (1.3) and haven't found anything like this.
    Any help would be greatly appreciated!!!

    So why do you say the error has something to do with negative numbers when (in your own words): "all values (negative or positive) are showing up as zero"? I don't know what your problem is, but negative numbers probably ain't it.

  • Chart / graph won't show negative values (Keynote '08)

    Hi, I have a range of values from -100 to +100. When I edit the source data accordingly, the line only shows value from 0 upwards. all negative values are shown as Zero 0. problem occurs in numbers too, and also carries over to an export.
    Am I missing something? This is getting a bit urgent, and I do hope that I don't have to blame my mac for the delay - it would be less embarrassing if it was my ignorance.
    Ian

    Keynote and Numbers are definitely able to graph negative numbers, and given that both of them are showing this problem for you, I'd suggest re-installing the iWork suite.

  • Negative Numbers considered as VARCHAR while uploading CSV file under Data Load in APEX

    I am trying to upload a CSV file which contains negative numbers. These negative numbers are being considered as VARCHAR2 while uploading. And if I change the Column Type to Numbers the upload fails.
    Any solutions the problem will highly be appreciated.

    select * from nls_database_parameters
    where parameter = 'NLS_NUMERIC_CHARACTERS'
    shows you which characters your database believes represent the decimal place and the thousands separator. So, if your database expects 1,234.123 and you present a 'number' as 1 234,123 it will complain.
    Also, in your case... your comma-separated-values contain commas? Or are the individual fields enclosed with quotes?

  • How to know if there are more positive or negative numbers?

    I will try to explain my problem with an example, since in the computer I don't have labVIEW installed.
    I have 10 numbers and multiply it for 10 other numbers
    and of course i will have 10 results, after it I have to show the meddium value of this 10 results and have to show the signal that most appear (+ or -)
    My problem is to show the signal, if I have 7 negative numbers and 3 positive numbers, how can I measure it and show the negative signal in the final?
    example:
    -0,3 -0,8 1 0,3 0,6 -0,7 -0,1 -0,5 0,3 -0,4
    So i have to put in the final:
    - 0,5
    Thanks
    Solved!
    Go to Solution.

    Here is code that gives you -0.5 from the given data. Still, sounds pretty useless.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    minuszeropointfive.png ‏2 KB

  • Previewing Pages document in Preview shows page numbers incorrectly

    Previewing Pages (5.2) document in Preview (7.0) shows page numbers incorrectly. Regardless of starting page number preview shows as Page 1.
    Suggestions appreciated...

    That appears to be YABIP5 (Yet Another Bug In Pages 5].
    Pages .09 documents are fine.
    No prizes however for finding bugs in Pages 5/5.2 it's swarming with them.
    Peter

  • How to show Indian numbers in the Firefox ?

    How to show Indian numbers in the Firefox ?
    Like This : http://i52.tinypic.com/f1y3c5.png
    Not Like This : http://oi52.tinypic.com/23r0osm.jpg

    Thank you very much ..

  • How to show Ordinal numbers in Mac Mail

    How to show Ordinal numbers in Mac Mail?

    do it with the help of import-export wizard. Here goes the steps for youhttp://www.trickyways.com/2010/08/how-to-transfer-emails-from-outlook-to-apple-m
    ail/
    Your best move would be if you search for your problem on some search engine
    that you use.
    Typing "Convert
    Pst To Mac Mail" will land you in several solution.
    Or you can simply visit apple online store for this problem have a look:
    https://itunes.apple.com/in/app/pst-con
    ... 1009?mt=12
    Hope this helps

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

Maybe you are looking for