How to use equation in form calculations

  • Marcin Hrynowiecki
    Asked on January 12, 2022 at 10:39 PM

    Hi, I have this big equation that I am trying to put on jotform calculations and it doesn't seem to work. Would you be help out?
    In the places of F4, E4 and D4 i would number fields to fill in.
    =495/(1.0324-0.19077*log10(F4-E4)+0.15456*log10(D4))-450

  • Saeed Support Team Lead
    Replied on January 13, 2022 at 3:56 AM

    Hi there, Thanks for reaching out to support.

    Could you please provide us a bit more information on your requirement and share with us the relevant form URL so that we can assist you accordingly.

    We will be waiting for your response


  • biofitnessmh
    Replied on January 13, 2022 at 7:52 AM

    Hi,

    Thanks for your response. Please find attached a link to the form I am creating. Basically, I am trying to make a simple body fat calculator using the following formula and the calculation isn't just right. Are there any special rules for such complex calculations?


    BFP =4951.0324 - 0.19077×log10(waist-neck) ) + 0.15456×log10(height)- 450


    https://form.jotform.com/220107394504044







  • Cecile JotForm Support
    Replied on January 13, 2022 at 8:30 AM

    Hello,

    Can you please provide us a sample calculation to confirm if we get the same answer?

    Awaiting your response.

  • biofitnessmh
    Replied on January 13, 2022 at 9:12 AM

    495/(1.0324-0.19077*log(10)*(91-40)+.15456*log(10)*(185))-450 =


    The result on calculator is -425.12..... where the same equation plugged into excel sheet would give me 18.3

  • Harvey JotForm Support
    Replied on January 13, 2022 at 10:04 AM

    Hello,

    Please allow me time to check this. I will get back to your shortly.

    Thank you.

  • Harvey JotForm Support
    Replied on January 13, 2022 at 10:40 AM

    Hello,

    Thank you for waiting!

    The formula being entered on excel is resulting to 412.12 on excel.

    1642088106 61e046aae92b7  Screenshot 10

    Upon checking your formula on excel it is resulting in 18.27 if the '10' on the 'log(10)' is removed.

    1642087530 61e0446a6073f  Screenshot 21

    As per our guide, the Log10 on Jotform results to 2.3026 and the Log(2) results to 0.69 which is different from the result using the excel calculation. Kindly check our guide in Math Function reference in building your formula.

    Form Calculation – Math Function Reference

    Let us know if you have any questions.

  • biofitnessmh
    Replied on January 14, 2022 at 8:36 AM

    Hi. Thank you for your help. Still, I don't know what function to use to make it work. I think I have tried everything. Would you have any suggestions?


    Thank you.

  • Nina_J
    Replied on January 14, 2022 at 9:08 AM

    Hello,

    Let me check further. Please allow me some time to review this.

    Thanks!

  • Nina_J
    Replied on January 15, 2022 at 6:56 AM

    Hello,

    I've tried multiple tests as well and followed this guide https://www.jotform.com/help/267-form-calculation-math-function-reference/, but I am unable to get the desired result.

    Please give me more time to figure out something.

    Thank you!

  • igorbojczuk
    Replied on January 15, 2022 at 8:26 AM

    Hi,

    There are two things to keep in mind in order for this NHRC body fat equation to work as expected:

    1. There is no log_10(x) in Jotform, so the function you have typed out log10 will not work. I understand that this can be confusing, but in Jotform log() stands for the Natural Logarithm, not the Common Logarithm (a reminiscence from underlying Javascript, where it calls out the natural ln function Math.log()).

      TLDR: Natural logarithm log(x) needs to be first converted to log_10(x). To do that, we simply need to multiply log(x), by log_10(e), which equals to roughly 0.434, therefore:

      log_10(x) = log(x) * 0.434

      We can now write out your formula as:

      BF% = 495/ (1.0324 - 0.19077 * log(w-n)*0.4343 + 0.15456 * log(h) * 0.434) – 450

    2. The second thing is that Jotform might sometimes have some issues with detecting the calculation order, so when getting some weird results, it is a good practise to add some parenthesis, to ensure the equation gets interpreted correctly.

      BF% = 495/ (1.0324 - 0.19077 * (log(w-n)*0.4343) + 0.15456 * log(h) * 0.434) – 450

      The equation above is a final tested version that you can see working in a cloned version of your form:

      https://form.jotform.com/220143349118954


    Kind Regards,

  • biofitnessmh
    Replied on January 15, 2022 at 9:30 AM

    Hi.


    Thank you so much for all your help figuring this out. As much as it is confusing it does make sense. Thank you for all the explanation as well.

    I can see that your cloned version works perfectly, however once I put provided formula I still don't get the desired result. Would you mind having a look at the screenshot of what I have put and see if I am a making a mistake with something or not.1642257044 61e2da9426951 Screenshot 2022 Screenshot 101642257044 61e2da943d2e4 Screenshot 2022 Screenshot 21

  • igorbojczuk
    Replied on January 15, 2022 at 9:53 AM

    Hi,
    Apologies, this one is actually on me, the added parenthesis should be one value earlier:
    BF% = 495/ (1.0324 - ( 0.19077 * log(w-n)*0.4343 ) + 0.15456 * log(h) * 0.434) – 450


    Best,

  • biofitnessmh
    Replied on January 15, 2022 at 10:32 AM

    Thanks again. Would you kindly check this again for me? I added extra brackets that won't really affect anything but or still is not working for me. 1642259461 61e2e4054c7e5 20220115 150549 Screenshot 10

  • Saeed Support Team Lead
    Replied on January 15, 2022 at 12:13 PM

    Hi there,

    Thanks for getting back to us.

    I have cloned my colleague's sample form and edited the calculation based on the details that you have provided.

    Please check and let us know how it goes.

    Sample Form URL: https://form.jotform.com/220145190074951

    Complete guide 👉 How to Clone an Existing Form From a URL

    Output:

    1642266690 61e30042506fd  Screenshot 10

    I hope to hear good news from you. Thank you!

  • biofitnessmh
    Replied on January 15, 2022 at 2:50 PM

    Hi,


    Thank you so much for your help. I cloned it as per instruction and it works fine. I am still curious why mine didn't work as I compared the formulas and they are exactly the same.

    I can't thank you enough for your support as I couldn't have done it without it. I really apriciate it.