Using Calculations

Calculations are available within a field when using a Number field with calculation enabled, or a Product field set to Field Type of Calculation.

In this guide, we will show you how to set up a calculation in a Number field, as well as go over some important rules on using number fields in calculations as well as the rules supporting different decimal formats.

Creating a calculation formula

To demonstrate how the calculations works we will generate a simple example of a calculation using two Number fields.

  1. Add two different number fields and name them First Number and Second Number.
  2. Save your form, it is important to do this so the newly added fields are available when setting up the calculation formula in later steps.
  3. Add a third Number field which will handle the result of the calculation. Name it Total.  Ensure that this field is positioned after the first two Number fields.
  4. Access the field settings of the Total field.
  5. Select the Enable Calculation checkbox to enable this field to be populated based on a calculation result. Once the Enable Calculation checkbox is selected, additional options will appear below it.
Woorise form number field enable calculations
  1. Access the field settings of the Total field. Click the button Insert Merge Tag and select your first field in the calculation. Note that only fields valid for use in calculations will be listed.
woorise number field calculations insert merge tags
  1. Add a mathematical operator. In this case, simple addition (+).
  2. Insert the Second Number field to complete the calculation.
  3. Check the calculation by clicking Validate Formula. If it says that your calculation is invalid, go back and take another look.
woorise number field calculations validate formula
  1. Your calculation is all set. Be sure you Save your form.

Advanced calculations

Advanced calculations empower you with advanced mathematical functions and conditionals, it improves the formula editing experience with a powerful new editor, complete with syntax highlighting, autocompletion, shorthand field references, and so much more! (available on Pro plan)

Merge tag shorthand

The default formula uses merge tags to reference fields. Merge tags are referenced using the field ID, with or without the descriptor, such as {Field A:1} or {:1}.

Advanced calculations adds shorthand for fields to clean up your calculations and make it easier to keep track of everything. The shorthand for the same field shown above is written as F1. Shorthand offers more readable calculations, especially for complicated functions.

woorise form number field advanced calculations Merge Tag Shorthand

Conditional statements

if/else

if( F1 > 1.25 && F1 < 5.5 ):
	F1 * 50
else:
	0
endif;

if/elseif/else

if( F1 < 5.5 ):
	F1 * 50
elseif( F1 >= 10 ):
	F1 * 25
else:
	0
endif;

Supported operators

The following comparison operators are supported:

  • == Equal to
  • != Not equal to
  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to

Multiple Expressions

Conditional statements support multiple expressions within a single condition via the the && (and) or the || (or) operators.

To require both expressions to be true for the condition to match, you would use the && operator. In this example, the condition will only be true if Field #1 is greater than 5 and less than 10.

if ( F1 > 5 && F1 < 10 ):

If you would like your condition to match if any of the conditions are true, you would use the || operator. In this example, the condition will return true if Field #1 is greater than 5 or if Field #2 is greater than 5.

if ( F1 > 5 || F2 > 5 ):

While these examples are simple, this functionality is quite robust and can handle conditions that contain expressions with both && and || operators.

Syntax Highlighting

Advanced calculations uses syntax highlighting and autocompletion to the calculation text area. Syntax highlighting drastically improves the readability of calculations, especially complicated ones that use conditional statements and functions.

woorise form advanced calculations syntax highlighting

Autocompletion aids you when inputting a function or conditional statement. When you start typing any supported function, the editor will suggest a completion. Click the suggested function (or hit return) to insert the full function with placeholder values.

woorise form advacned caluclations autocompletion

The editor also automatically closes parentheses and merge tag braces. Say goodbye to invalid formulas because of an errant parenthesis!

Functions

The following functions are supported to both save you time and effort and provide more accurate results.

  • abs Returns the absolute value of a number.
  • average Returns the average value of the arguments given.
  • ceil Rounds a number up to the next largest integer.
  • exp Returns e^x, where e is Euler’s number (~2.718) and x is the provided value.
  • floor Rounds a number down to the nearest integer.
  • fv Calculates the future value of an investment based on constant-amount periodic payments and a constant interest rate.
  • ln Returns the logarithm of a number, base e. e is Euler’s number (~2.718).
  • log Returns the logarithm of a number, base 10.
  • max Returns the largest value in the list of arguments.
  • min Returns the smallest value in the list of arguments.
  • pi Returns the value of pi to 20 decimal places.
  • round Rounds a number to the nearest integer.
  • sqrt Returns the square root of a number.

Sample usage

round( 12.7 )
round( F2 )

Example

In the below example, the returned value is 9.

round( 8.68 )

Rules

  • When creating a calculation formula, all numbers manually entered in the formula must:
    • Be entered in decimal dot format “.”
    • Use a preceding 0 if required. Example: 0.2 is valid, 0,2 or .2 is not valid.
  • When entering number fields on a form on the front end of the campaign, users must enter the format configured for that number field, even if that field is being used in a calculation that uses a different number format.
  • When using drop down or checkbox field types in a formula, the values must be formatted with the same format as the field containing the formula.
    For example, if you have a calculated number field in decimal comma format (i.e. 9.999,99) that has calculation formula that references a drop down field, the values of the drop down field must be also be in decimal comma format.
  • If the number field is configured with a “Currency” Number Format, the drop down values must be formatted with the same decimal separator as the currency.
  • When using a quantity drop down field to specify fractional values (i.e. 5.5), those numbers must be formatted with the same decimal separator as the site’s currency.
  • ​​​​​​Fields referenced in a calculation formula (1) must be positioned before the calculation field, and (2) must not be hidden by logic. This is because calculations are rerun during submission using saved values, and if the field hasn’t been saved yet or has been ignored due to logic at form submission, it won’t have a value available for the calculation, leaving the result either incorrect or empty.

Not quite what you’re looking for?

Contact our support team through email and chat or get the job done with a pro.

Join more than 80,000 brands using Woorise

Easily create landing pages, forms, surveys, quizzes & viral giveaways that drive real user engagement.