• Resolved UserDG

    (@tenkepadu)


    I have two questions,

    1) for formula, I have a formula like this:

    Round up(price-downpayment over 1- (1 over (1 + interest over 12)) over interest over 12

    I convert it to…
    Round up (fieldname1-fieldname2/1-(1/(1+fieldname3(which is dropdown)/12)) / fieldname3 /12

    is this correct? What is the correct formula?

    2) It is possible to compute if every amount have different interest range? E.g 5,000 to 12, 000 the interest is 20.18% while 12,001 to 30,000 the interest is 25.50%

    How can I do that? If the client is inputted 5,000 so the interest will be 20.18%. Should I use dropdown?

    https://ww.wp.xz.cn/plugins/calculated-fields-form/

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

    (@codepeople)

    Hi,

    The ROUND UP in javascript is the CEIL operation. The equation’s description is not correct, you should use parenthesis to preserve the priority of the operations. For example, fieldname2/1 = fieldname2, so there are some parenthesis that are missing.

    So, you should check first the correct structure to the equation’s description.

    About the selection of a different interest based in the price, you can use conditional statements, similar to:

    (function(){
    var interest = 0;
    if(5000<=fieldname1 && fieldname1<=12000) interest=20.18;
    if(12001<=fieldname1 && fieldname1<=30000) interest=25.5;

    return the_equation_here_using_the_interest_variable;
    })()

    Best regards.

    Thread Starter UserDG

    (@tenkepadu)

    I did some changes. I create fieldname1 (dropdown for price range) 5,000 – 12,000 then fieldname2 for downpayment, fieldname3 (dropdown with interest and no. of term) and fieldname4 for monthly payment

    PREC(fieldname1-fieldname2 over 1- (1 over (1 + fieldname3 over 12))) over fieldname4 over 12

    convert to

    PREC(fieldname1-fieldname2 / 1- (1 / (1 + fieldname3 over 12))) / fieldname4 / 12

    is this correct?

    Thread Starter UserDG

    (@tenkepadu)

    and what do you mean in return the_equation_here_using_the_interest_variable; ?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    PREC(fieldname1-fieldname2 / 1- (1 / (1 + fieldname3/12))) / fieldname4 / 12

    The structure of the equation is right programmatically? Yes. But the equation represent the value you want obtain? I don’t know, it depend of the business logic you want represent.

    In the first entry, you’ve asked me about the use of an interest value, depending of the price. I don’t know in your equation the variable that represent the interest. With the structure I’ve recommended, you can determine the interest in function to the price, and then use this variable in the equation you describe, and return it.

    Best regards.

    Thread Starter UserDG

    (@tenkepadu)

    Where can I put the equation that you recommended?

    Thread Starter UserDG

    (@tenkepadu)

    What is the proper value in the dropdown for price range? 5,000 – 12,000 is this enough?

    Thread Starter UserDG

    (@tenkepadu)

    I think I can’t use your recommendation because in every product there’s a price range, in every price range there’s different interest.

    I did is in every product (dropdown) has different price range (dropdown) and in every price range has different interest with no. of terms (dropdown)

    Now, I add 1 textbox to put the amount of the product. Like this

    Amount -> Downpayment -> Product(dropdown) -> Price Range(dropdown) -> No. of terms(dropdown) -> Monthly Payment (this is how will compute the monthly payment)

    How can I base or rely the inputted amount in price range?

    E.g If the client input 10,000 and his downpayment is 2,000 and price range for this is 5,000 – 12,0000 and no. of terms is 9 months = monthly payment

    Thread Starter UserDG

    (@tenkepadu)

    Is this correct? I put the formula that you recommend in calculated field

    (function(){
    var interest = 0;
    if(5000<=fieldname1 && fieldname1<=12000) interest=99.40;
    if(12001<=fieldname1 && fieldname1<=30000) interest=97.55;

    return PREC(fieldname1-fieldname2 / 1- (1 / (1 + fieldname3/12)) / fieldname3 / 12,2);
    })()

    Thread Starter UserDG

    (@tenkepadu)

    fieldname1 = amount
    fieldname2 = downpayment
    fieldname3 = terms with interest

    If the interest already declare in “if”. How can I call the interest in return? Or it still necessary to put the interest in no. of terms?

    Thread Starter UserDG

    (@tenkepadu)

    What is the equivalent of ^ in programmatically?

    Here..

    PREC(fieldname1-fieldname2 / 1- (1 / (1 + fieldname3/12) ^ fieldname3) / fieldname3 / 12,2)

    Should I create a new fieldname for interest only? Or its enough to combine the interest and no. of terms?

    If yes, should I need to create a new field for interest, how can I partner/equivalent the value of interest rate in separate field of no. of terms?

    If I have field for interest and another field for no. of terms

    Thread Starter UserDG

    (@tenkepadu)

    I have now a new formula

    PREC(amount-downpayment / 1- (1 / (1 + interest/12)exp(no.of terms)) / interest/ 12)

    PREC(fieldname1-fieldname2 / 1- (1 / (1 + fieldname3/12)exp(fieldname3)) / fieldname3 / 12)

    Now how can I declare the interest rate if the interest is declare here if(5000<=fieldname1 && fieldname1<=12000) interest=99.40;
    if(12001<=fieldname1 && fieldname1<=30000) interest=97.55;

    Thread Starter UserDG

    (@tenkepadu)

    I have this formula

    (function(){
    var interest = 0;
    if(5000<=fieldname1 && fieldname1<=12000) interest=99.40;
    if(12001<=fieldname1 && fieldname1<=30000) interest=93.51;

    return PREC(fieldname1-fieldname2 / 1- (1 / (1 + interest/12)exp(fieldname3)) / interest/ 12,2);
    })()

    I put this in monthly payment field but it’s not working

    Plugin Author codepeople

    (@codepeople)

    Hi,

    You shoul use all mathematic operators in the equations 😉 You’ve forgot the multiplication operator.

    PREC(fieldname1-fieldname2 / 1- (1 / (1 + interest/12)*exp(fieldname3)) / interest/ 12,2);

    Best regards.

    Thread Starter UserDG

    (@tenkepadu)

    I see +1 😉

    It is possible to do this
    CEIL(PREC(fieldname1-fieldname2 / 1- (1 / (1 + interest/12)*exp(fieldname3)) / interest/ 12,2)) ? So that the monthly payment will be round upward

    Plugin Author codepeople

    (@codepeople)

    Hi,

    If you simply want round upward, the PREC operatior is not necessary.

    CEIL(fieldname1-fieldname2 / 1- (1 / (1 + interest/12)*exp(fieldname3)) / interest/ 12)

    But if you want that the result include two decimal places, even with zeros, you should use the PREC operation as the last operation applied to the equation:

    PREC(CEIL(fieldname1-fieldname2 / 1- (1 / (1 + interest/12)*exp(fieldname3)) / interest/ 12),2)

    You can ask, but what happen if I want rounding the number with a bigger precission?. For example, 183.2567 to 183.26

    In this case you should use a trick, multiply the equation by 100, round the result, and divide it by 100 again:

    PREC(CEIL((fieldname1-fieldname2 / 1- (1 / (1 + interest/12)*exp(fieldname3)) / interest/ 12)*100)/100, 2)

    Best regards.

Viewing 15 replies - 1 through 15 (of 29 total)

The topic ‘Right formula’ is closed to new replies.