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

    (@codepeople)

    Hi norganics,

    In the mathematical equations if the field is empty, the plugin assumes that its value is zero, so the equation in this case would as simple as:

    fieldname2*2

    Best regards.

    Thread Starter norganics

    (@norganics)

    Hi Codepeople,

    I guess I used too simple an example. Here’s the real equation:

    PREC(IF(fieldname4<0.1,0,(fieldname3*200*(fieldname4/100))-fieldname2),2)

    I used <0.1 because if I don’t fieldname5 starts calculating before fieldname 4 has anything in it…which is why I wanted to use “null.”

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Your equation has a correct format, but it can be simplified as follows:

    PREC(IF(fieldname4,0,fieldname3*200*fieldname4/100-fieldname2),2)

    Best regards.

    Thread Starter norganics

    (@norganics)

    That equation works but doesn’t solve the problem. As soon as a datum is entered in fieldname2, fieldname5 calculates before it has data in fieldname3 and fieldname4. When I used the logical expression IF(fieldname4<0.1,0, then fieldname5 remains zero until there’s a value in fieldname4. It solves the problem but I thought there’d be a better way to do it. Thanks for your help.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    For example, if you want to evaluate the equation only if the values of fields: fieldname2, fieldname3, and fieldname4 are different to zero, the equation would be as simple as:

    PREC(IF(AND(fieldname2,fieldname3,fieldname4),0,fieldname3*200*fieldname4/100-fieldname2),2)

    Remember the plugin replaces the empty values by zero before evaluate the equations, if you want be sure simply that these fields are not empty, you can assign a class name to each field, for example: f2, f3, and f4 respectively, and modify the previous equation as follows:

    (function(){
    var v2 = jQuery('.f2 input').val();
    var v3 = jQuery('.f3 input').val();
    var v4 = jQuery('.f4 input').val();
    
    return  PREC( IF( AND( v2 != '', v3 != '', v4 != '' ), 0, fieldname3*200*fieldname4/100-fieldname2 ), 2);
    
    })()

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Expression for null fields’ is closed to new replies.