Jotform - calculation - JavaScript

  • Profile Image
    RHemery
    Asked on June 28, 2017 at 05:03 AM

    Hi - I've created a calculation form in JotForm:

    http://www.bedford.ac.uk/newfees/part-time-level2.html?courseFee=1000

     

    However I can't figure out how to get the calculation to not have a decimal place, i.e. be £1000 not £1000.00

     

    Could anyone help?

     

    Thanks

     

     

    Rich

  • Profile Image
    EltonCris
    Answered on June 28, 2017 at 05:37 AM

    You can remove it by unchecking the following option in the calculation wizard.

    In the calculation wizard, click the 3 dots to open the calculation options

    Then uncheck "Show empty decimal places".

    Hope this helps!

  • Profile Image
    RHemery
    Answered on June 28, 2017 at 05:39 AM

    Hi - sorry I should have said, the form isn't using the inbuilt JotForm calculation function, it's other code.

  • Profile Image
    Charlie
    Answered on June 28, 2017 at 06:30 AM

    I'm not really sure why you are using a script to do calculations here and why the form is embedded on your website using the full source code. However, I presume this is the script that responsible for the calculation:

     

    Your script uses toFixed() function which declares a decimal point to the said value. Here it is set to 2 which is why you are getting 2 decimal places. If you want to remove the decimal places, then you can try using the following functions:

    Math.trunc() (truncate fractional part, also see below)

    Math.floor() (round down)

    Math.ceil() (round up)

    Math.round() (round to nearest integer)

     

    You can also contact the developer who created the script to have a more better approach.

    If in case you will using JotForm's own features for calculations, you can check the following guides:

    https://www.jotform.com/help/259-How-to-Perform-Form-Calculation-Using-a-Widget 

    https://www.jotform.com/help/268-Conditional-Logic-Inserts-Text-Calculation-Into-A-Field 

     

    I hope that helps. 

  • Profile Image
    RHemery
    Answered on June 28, 2017 at 07:42 AM

    Thanks I just need to amended the toFixed to 0, rather than 2.

    I built the form ages ago using JotForm because it was simple for the conditional logic, and it's the source code version because I pass the course fee through the URL (it's a College website) that has fees for diff courses.

  • Profile Image
    Sven
    Answered on June 28, 2017 at 08:51 AM

    As my colleague mentioned, you can contact the developer to amend the code. And if you want you can use JotForm functionalities, you can also set the payment integration to accept a user defined amount rather then a fixed amount, and you can redirect results to external pages. 

    Let us know if you need any further help.