• Resolved inicslab

    (@inicslab)


    How do i sum up the below equation?

    (function(){
    if(fieldname5 < 10164) return 0;
    if(fieldname5 > 0 && fieldname5 > 10164) return fieldname5*0.01;
    if(fieldname5 > 10165 && fieldname5 <19740) return fieldname5*0.15;
    if(fieldname5 > 19741 && fieldname5 < 29316) return fieldname5*0.20;
    if(fieldname5 > 29317 && fieldname5 < 38892) return fieldname5*0.25;
    if(fieldname5 > 38893) return fieldname5*0.30;

    })();

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter inicslab

    (@inicslab)

    (function(){
    if(fieldname5 < 10164) return 0;
    if(fieldname5 > 0 && fieldname5 > 10164) return fieldname5*0.01;+
    if(fieldname5 > 10165 && fieldname5 <19740) return fieldname5*0.15;+
    if(fieldname5 > 19741 && fieldname5 < 29316) return fieldname5*0.20;+
    if(fieldname5 > 29317 && fieldname5 < 38892) return fieldname5*0.25;+
    if(fieldname5 > 38893) return fieldname5*0.30;

    })();
    to reflect something like that in a javascrict statement

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Your equation includes exclusive conditional statements with “return” instructions. For example:

    If fieldname5 is between 0 and 10164, it cannot be between 10165 and 19740 too, both conditional statements, and the rest of conditional statements in your equation are exclusives. So, What is in reality the equation’s behavior you want get? Could you describe the equation, please?

    Furthermore, the conditions in the second instruction are wrong:

    if(fieldname5 > 0 && fieldname5 > 10164) return fieldname5*0.01;

    because if fieldname5 is greater than 0 it would be greater than 10164 too, and are not evaluated the rest of the conditional instructions in the equation.

    Best regards.

    Thread Starter inicslab

    (@inicslab)

    (function(){

    if(fieldname5 < 10164) return 0;
    if(fieldname5 > 0 && fieldname5 < 10164) return fieldname5*0.01;
    if(fieldname5 > 10165 && fieldname5 <19740) return fieldname5*0.15;
    if(fieldname5 > 19741 && fieldname5 < 29316) return fieldname5*0.20;
    if(fieldname5 > 29317 && fieldname5 < 38892) return fieldname5*0.25;
    if(fieldname5 > 38893) return fieldname5*0.30;

    })();

    in need to reflect the table below

    From To Taxable Pay
    1 10,164 10,164.00 10% 1,016.40
    10,165 19,740 9,576.00 15% 1,436.40
    19,741 29,316 9,576.00 20% 1,915.20
    29,317 38,892 9,576.00 25% 2,394.00
    38,893 – 161,108.00 30% 48,332.40

    for example if one earns 100,000 to get taxed in all groups summing up 1,016.40+1,436.40+1,915.20+2,394.00+48,332.40

    but if earning less than 10,164 to be exempted from tax.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    In this case the equation would be:

    (function(){
    var f = fieldname5, r = 0;
    if( (f - 38893) > 0 ){ r += (f - 38893)*0.3; f = 38893; }
    if( (f - 29317) > 0 ){ r += (f - 29317)*0.25; f = 29317; }
    if( (f - 19741) > 0 ){ r += (f - 19741)*0.2; f = 19741; }
    if( (f - 10165) > 0 ){ r += (f - 10165)*0.15; f = 10165; }
    if( (f - 10164) > 0 ){ r += (f - 10164)*0.1; f = 10164; }
    return r; 
    })()

    If you need additional help with your project, I can offer you a custom coding service through my personal webpage:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter inicslab

    (@inicslab)

    Thanks man, It worked, Thumbs high.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sum if Statement’ is closed to new replies.