Title: Advanced Equation
Last modified: July 8, 2020

---

# Advanced Equation

 *  Resolved [vacoas](https://wordpress.org/support/users/vacoas/)
 * (@vacoas)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/advanced-equation/)
 * 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](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/advanced-equation/#post-13096142)
 * Hello [@vacoas](https://wordpress.org/support/users/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](https://wordpress.org/support/users/vacoas/)
 * (@vacoas)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/advanced-equation/#post-13096361)
 * Hello [@codepeople](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

## Tags

 * [custom calculator](https://wordpress.org/support/topic-tag/custom-calculator/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 2 replies
 * 2 participants
 * Last reply from: [vacoas](https://wordpress.org/support/users/vacoas/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/advanced-equation/#post-13096361)
 * Status: resolved