--- title: "Calculate" slug: "frebehav-calculate" updated: 2026-05-04T06:39:28Z published: 2026-05-04T06:39:28Z canonical: "docs.lobstersoftware.com/frebehav-calculate" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # Calculate *See also:* [Calculation field](/v1/docs/en/fre-calc) > [!NOTE] > The **Behavior type** [Calculate](/v1/docs/en/frebehav-calculate) executes a [Calculation expression](/v1/docs/en/core-raw-parser) that can be used in many ways to evaluate data available in the context of a form or to extract new data from it. > > The optional check expression influences whether the actions are executed on "true" or "false" by returning a value that can be interpreted as a truthy/falsy value. The input value `$input` is the output value of the expression above. However, the variable "orgInput" can also be used to access the original input value of the behavior (*$var(orgInput)*). ![images/download/attachments/177913913/image-2024-9-25_15-53-57-version-1-modificationdate-1727272436828-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-9-25_15-53-57-version-1-modificationdate-1727272436828-api-v2.png) The **Behavior type** [Calculate](/v1/docs/en/frebehav-calculate) executes a [Calculation expression](/v1/docs/en/core-raw-parser) that can be used in many ways to evaluate data available in the context of a form or to extract new data from it. The return value of the "calculation" overwrites the original input data (`$input`) of the behavior. However, the **Calculation expression** can refer to input data (e.g. by `$input`) provided by a [Events (Form designer)](/v1/docs/en/fretrigger) (e.g. [Changed](/v1/docs/en/fretrigger-changed)) or from a calling behavior (see [Execute behavior](/v1/docs/en/freaction-execute-behaviour)). The rest of the procedure depends partly on whether an optional **Check expression** has been configured to determine a Boolean value by another [Calculation expression](/v1/docs/en/core-raw-parser) for the selection of the actions (on "true"/"false") to execute. Overall, the following cases must be differentiated: - If the **Calculation expression** contains syntactical errors (e.g. regarding the use of parentheses), the **Actions on "false"** will be executed. An error message is assigned as input data (`$input`). Any **Check expression** that has been defined is then not evaluated. The original input value of the behavior can be accessed via the orgInput variable (*$var(orgInput)*) - If no **Check expression** is defined, then the return value from a syntactically correct **Calculation** **expression** (`$input`) is passed to the **Actions on "true"**. This is also the case if the return value is empty (`$null`), which happens, for example, with a "division by 0". - If a **Check expression** is defined, it is evaluated as a [Calculation expression](/v1/docs/en/core-raw-parser) whereby the return value from the already evaluated **Calculation expression** provides the input data (`$input`). - If the **Check expression** contains syntactical errors (e.g. regarding the use of parentheses), the **Actions on "false"** will be executed. An error message is assigned as input data (`$input`). - If the result of the **Check expression** is not considered *false* according to the following table, the input data (`$input`) from the **Calculation expression** is passed to the **Actions on "true"**. - If the result of the **Check expression** is interpreted as *false* according to the following table, the input data (`$input`) from the **Calculation expression** is passed to the **Actions on "false"**. | Data type | Values that are considered false ("falsy"): | | --- | --- | | (none) | null (`$null`) | | Boolean value | `false` | | Number | 0 | | Text | "", "0", "false", "no" (not case sensitive) | ## Example A numeric input field (for integers) should determine and display whether the assigned numeric value is even or odd, each time the value is changed. | ![images/download/attachments/177913913/image2020-5-8_16-10-18-version-1-modificationdate-1727270243352-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2020-5-8_16-10-18-version-1-modificationdate-1727270243352-api-v2.png) | ![images/download/attachments/177913913/image2020-5-8_16-10-42-version-1-modificationdate-1727270243347-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2020-5-8_16-10-42-version-1-modificationdate-1727270243347-api-v2.png) | | --- | --- | Configuration: | ![images/download/attachments/177913913/image-2024-9-26_9-19-27-version-1-modificationdate-1727335166541-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-9-26_9-19-27-version-1-modificationdate-1727335166541-api-v2.png) | - A behavior with the **Behavior type** [Calculate](/v1/docs/en/frebehav-calculate) is set up for the input field, which responds to the trigger [Changed](/v1/docs/en/fretrigger-changed) (not shown in screenshot) with all change types. --- - The **Calculation expression** [calc (Calculate expression)](/v1/docs/en/calc-function-calc) determines the remainder of an integer division of the input value (`$input`) by 2 ("modulo 2", see [Calculate value](/v1/docs/en/core-calculate-value-resolver)). For even numbers, this expression returns the value 0, for odd numbers it returns 1. --- - The **Check expression** uses the [cmp (Compare)](/v1/docs/en/calc-function-cmp) function to convert the result returned (`$input`) by the **Calculation expression** into a Boolean value: - If `$input = 0`, `$cmp` will return "true" and the **Actions on "true"** are relevant. - Otherwise `$cmp` returns "false" and the **Actions on "false"** are relevant. - --- Under **Actions on "true"**, the action [Set hint](/v1/docs/en/freaction-set-hint) sets the text to "even number" for the **Target element.** - --- Under **Actions on "false"**, the action [Set hint](/v1/docs/en/freaction-set-hint) sets the text to "odd number" for the **Target element.** | | --- | --- | > [!NOTE] > **NOTE:** > > Since the number 0 in the **Check expression** is interpreted as "false" (see table above), it could be assumed that in this example the **Check expression** `$not($input)`would give the same results as `$cmp($input,=,0)`. But this is not the case, because for the function [not (Logical negation)](/v1/docs/en/calc-function-not), every value that is not matching "true" (case-insensitive) is considered "false". However, assigning `$input` directly as a **Check expression** and swapping the two [Set hint](/v1/docs/en/freaction-set-hint) actions would yield appropriate results.