Automate your calculations with the Calculation element.
Presentation of the Calculation field.
Insert a calculation field and access its features: Go to the element options by clicking on the pencil. Several options are available to you under the Properties tab:
- Define how many digits after the decimal point will be included in your results.
- Define the type of results in your calculation: number or time.
- By checking the Editable entry box, you can change the results of your calculation. For example, if you want to round the results.
Under the Calculation tab, you will define the fields to calculate. The Calculation tool has several functions.
Conditional operators
You can condition your calculations through different operators:
List of operators
Arithmetic operators:
- + : addition and concatenation of text
- - : substraction
- / : division
- * : multiplication
- % : modulo or remainder of Euclidean division
Comparison operators:
- < : lesser than
- <= : Less than or equal to
- > : greater than
- >= : greater than or equal to
- == : equality
- ! = : inequality
- === : strict equality
- !== : strict inequality
Logical operators:
- && : logical operator AND
- || : logical operator OR
- ! : negation
- ? : ternary operator. It is written in the form: ((condition)? Value_if_true: value_if_false)
Bitwise operators:
- & : AND "bitwise"
- | : OR "bitwise"
Examples:
OR Function (||)
To perform a calculation if a box is checked or if an item is entered, you can use this formula:
- Our first condition || Our second condition? Value if true: Value if false
At first, we will test the first condition, if it turns out wrong, we will test the second, so on. In the example below, we test our input field. If it contains 0, 2, 4, 6, 8 or 10, then Even will appear, otherwise it will be Odd. Warning: if you add text, remember to remove the + which is generated automatically.
Note: we could also have used the percentage (%) to perform this operation. The Percentage allows to display the rest during a division. Thus, if the number is even, the division will not have any remainder and the calculation will be equal to 0.
AND Function (&&)
To perform a calculation if a box is checked and an item is entered, you can use this formula:
- Our first condition && Our second condition? Value if true: Value if false
In the example below, we wish:
- Make a reduction of 10 € if the box New customer is checked
- Add a 10% or 20% VAT if the respective boxes are checked.
Thus, we test respectively:
- If the box New customer is checked
- If the box New customer and VAT 10% are ticked
- If the box New customer and VAT 20% are ticked
- If the 10% VAT box is checked
- If the VAT 20% box is checked,
Warning: if you add text, remember to remove the + which is generated automatically.