• Resolved tax50

    (@tax50)


    I am using the Calculated Fields Form plugin on my word press website.

    I need to know how to create a calculation of some sort that will reduce the value in a box by 1 for every 2 that another number increases. and then it stops at a certain point. for example:

    if your income is above £100,000 your allowance will decrease by £1 for £2 extra that you earn up to a maximum of £125,000.

    at the moment i have:

    fieldname78 is the result of a previous calculation.

    fieldname79 is just a number field with the value £12,500 in it.

    I am typing this calculation in to a different field using a calculate button provided in the plugin.

    function(){
    if (fieldname78 = 100000) return (fieldname79)
    if (fieldname78 = 100002) return (fieldname79-1)
    if (fieldname78 = 100004) return (fieldname79-2)
    if (fieldname78 = 100006) return (fieldname79-3)
    if (fieldname78 = 100008) return (fieldname79-4)
    if (fieldname78 = 100010) return (fieldname79-5)
    if (fieldname78 = 100012) return (fieldname79-6)
    if (fieldname78 = 100014) return (fieldname79-7)
    if (fieldname78 = 100016) return (fieldname79-8)
    if (fieldname78 = 100018) return (fieldname79-9)
    if (fieldname78 = 100010) return (fieldname79-5)

    Now short of copying and pasting this same code 25,000 times i don’t know how to just make it do what i need within the range between £100,000 and £125,000. I want the result is reduced by £1 for every £2 increase in field 78 up to a maximum of £12,500.

    Please help, its been racking my brains, i have purchased the version i am using but cant seem to make it work like i want.

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

    (@codepeople)

    Hello @tax50

    In javascript, the operator for equality is the double symbol: “==” because the symbol “=” is used for assignment, however, I think your eqution can be implemented with some basic mathematical operations, conditional statements are not needed:

    
    fieldname79 - ROUND(MAX(fieldname78-100000,0)/2)
    

    and that’s all.
    Best regards.

    Thread Starter tax50

    (@tax50)

    wow thank you for your reply that is a lot better than i could have done and its working now.

    One slight problem, i want it to reduce by £1 each time field78 increases by £2. At the moment using your solution it reduces by £1 even though field 79 has only increased by £1.

    Is this a rounding error or something on my side that is causing this to happen?

    Your help and support is deeply appreciated.

    Plugin Author codepeople

    (@codepeople)

    Hello @tax50

    Use the FLOOR operation instead the ROUND one:

    
    fieldname79 - FLOOR(MAX(fieldname78-100000,0)/2)
    

    Best regards.

    Thread Starter tax50

    (@tax50)

    wow that worked perfectly thank you so much.

    Thread Starter tax50

    (@tax50)

    awe man i dont know what i have done now, but the result keeps coming up as a negative figure instead of positive, im sorry, im going to try it with ROUND again and see if that helps but then i will be back to the same problem.

    Plugin Author codepeople

    (@codepeople)

    Hello @tax50

    Please, be sure you have copied the code properly. I’ll try to describe it:

    
    fieldname79 - FLOOR(MAX(fieldname78-100000,0)/2)
    

    This piece of code MAX(fieldname78-100000,0) will return zero if fieldname78 is lesser thn 100000. So, if fieldname78 is 100013, MAX(fieldname78-100000,0) will returns 13.

    The FLOOR(X) operation returns the integer number equal or lesser than X, so, following with the previous example, the code would be:

    
    fieldname79 - FLOOR(MAX(fieldname78-100000,0)/2) = 
    fieldname79 - FLOOR(MAX(100013-100000,0)/2) = 
    fieldname79 - FLOOR(13/2) = 
    fieldname79 - 6
    

    That would be exactly the result with your original equation.

    And if the value of fieldname78 is lesser than 100000, for example: 90000

    
    fieldname79 - FLOOR(MAX(fieldname78-100000,0)/2) = 
    fieldname79 - FLOOR(MAX(90000-100000,0)/2) = 
    fieldname79 - FLOOR(0/2) = 
    fieldname79 - 0 = 
    fieldname79 
    

    One more time, the same result of your original equation.

    Best regards.

    Thread Starter tax50

    (@tax50)

    I am not faulting your formulae because for a brief second i saw it work, i think i have changed the field around or deleted it or something by accident. Please give me this one more time and i have started again.

    So, if your income is above £100,000 your allowance will decrease by £1 for each £2 extra that you earn up to a maximum of £125,000.

    at the moment i have:

    fieldname78 is the result of a previous calculation (the one with the income given in it)

    fieldname143 is just a number field with the value £12,500 in it.

    I want fieldname141 to display the result of this equation.

    I feel so bad too, because you actually fixed the problem for me before i changed the fields. Please one more time using these new updated fields i have got.

    Plugin Author codepeople

    (@codepeople)

    Hello @tax50

    If you have modified the fields, simply replace them in the equation, and that’s all. If the previous field was fieldname79 and you want to use fieldname143, then, replace their names in the equation.

    Best regards.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Reducing Increment Calculator’ is closed to new replies.