• Resolved vacoas

    (@vacoas)


    I am using the advanced equation editor to make a custom calculator.

    This part should return, in turn, 2%, 1.5%, 1% and .5% of the amounts specified. The equation works until 1.5% and thereafter continues to return 1.5% and not the lower % specified. The code is below. Thanks in advance for any help.

    (function(){
    if(fieldname2 <= 250000) return (fieldname2/50);
    else if(fieldname2 > 250000 <= 750000) return (fieldname2/100*1.5);
    else if(fieldname2 > 750000 <= 1750000) return (fieldname2/100);
    else if(fieldname2 > 1750000) return (fieldname2/200);
    })();

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

    (@codepeople)

    Hello @vacoas

    In javascript if you want check if a value or variable is into an interval, you should compare the variable with the low and high values of the interval, connecting them by the “and” operator, represented in javascript by double ampersand: “&&”

    So, the equation would be:

    
    (function(){
    if(fieldname2 <= 250000) return (fieldname2/50);
    else if(250000 < fieldname2 && fieldname2 <= 750000) return (fieldname2/100*1.5);
    else if(750000 < fieldname2 && fieldname2 <= 1750000) return (fieldname2/100);
    else if(1750000 < fieldname2) return (fieldname2/200);
    })();
    

    Actually, your equation includes unnecessary code. It can be simplified as follows:

    
    (function(){
    if(fieldname2 <= 250000) return fieldname2/50;
    if(fieldname2 <= 750000) return fieldname2/100*1.5;
    if(fieldname2 <= 1750000) return fieldname2/100;
    return fieldname2/200;
    })();
    

    Best regards.

    Thread Starter vacoas

    (@vacoas)

    Hello @codepeople

    Many thanks for your prompt assistance and taking the time to correct and simply the code. I’m hugely impressed with the support you provide on this forum

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Advanced Equation’ is closed to new replies.