• Resolved willc93

    (@willc93)


    Hello,

    I’m trying to get an if statement added and am having trouble. I want it so that if the number is negative the output is 0. I have everything working but cannot get the if to work. Here is my code:

    if((fieldname2 * (1.4/100) – (fieldname2 * (1.4/100) * fieldname13)) – fieldname2 * (1/100) < 0,0,(fieldname2 * (1.4/100) – (fieldname2 * (1.4/100) * fieldname13)) – fieldname2 * (1/100))

    I will also want the decimal to the third point. I am not sure how that will work once the if statement is in (I have it working now using PREC but without the if statement).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @willc93

    First, you should know the javascript is a case sensitive language, and you are confusing the “if” conditional statement in javascript whose structure is:

    
    if(condition)
    {
      operations if the condition is true
    }
    else
    {
      operations if the condition is false
    }
    

    with the “IF” operation distributed with the plugin, whose structure is:

    
    IF(condition, operations if true, operations if false)
    

    However, returning to your equation, you don’t need a conditional operation, only the MAX operation:

    
    MAX((fieldname2 * (1.4/100) – (fieldname2 * (1.4/100) * fieldname13)) – fieldname2 * (1/100), 0)
    

    and that’s all. In this case if the result of the mathematical operations is less than 0, the equation will return 0.

    Best regards.

    Thread Starter willc93

    (@willc93)

    @codepeople Thank you! I did not know about the MAX function until now and it did the trick.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help with if statement’ is closed to new replies.