• Resolved tomvanarken

    (@tomvanarken)


    I’m trying to link two equations together in a form that is supposed to give customers a price. The first equation sets a base price and the second equation adds some extra options. These equations work seperatly in two different Calculated Fields. But I can’t seem to link these two together to create one single price outcome.

    The first equation is:

    (function(){ if(fieldname2 < 11) return 50; if(fieldname2 > 10) return 50+2.5*(fieldname2-10); })

    The second equation is:

    fieldname2*(fieldname3+(fieldname6*2)+fieldname5)

    The end result should be equation 1 + equation 2.
    Can someone help me do this?

    Also I couldn’t find out how to let the outcome be with two decimals and a euro sign in front of it (like this: €53,50) So that it actually looks like a price.

    Thanks very much in advance

    https://wordpress.org/plugins/calculated-fields-form/

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    The correct structure for the first equation would be:

    (function(){ if(fieldname2 < 11) return 50; if(fieldname2 > 10) return 50+2.5*(fieldname2-10); })()

    you must to write the symbols ‘()’ at the end of the function if you are using the estructure: (function(){….})()

    If you want get the result with two decimals, you simply should use the PREC operation in the equation before returning the value, with the format: PREC(number, decimals)

    For example: PREC(1.1234,2) is equal to 1.12
    but PREC(1.1264,2) is equal to 1.13

    PREC( fieldname2*(fieldname3+(fieldname6*2)+fieldname5), 2)

    About the euro sign in fron to the resulting number. Please, select the calculated field, and type the euro sign in the attribute: “Symbol to display at beginning of calculated field”

    Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Linking two equations’ is closed to new replies.