# How to Use Math Calculations in Forms

## Basics

FormCrafts has a powerful built-in math engine. It can be used to make order forms with complex pricing, quizzes, quotations, etc ... Math calculations work in real-time.

Every field in FormCrafts has a unique ID in the format **fieldX**, where X is a number, for example: field1, field9, field32, etc ... FormCrafts allows you to use the value of any field to create math calculations in your forms.

## Example one

On the form edit screen go to **Add Field -> Basic** and add two **One-line input** fields to your form. When you click to edit the field you would be able to see the field ID for that field. Let's say these two fields have the ID **field4** and **field8**.

We will also add a custom text field to your form - to show the result of the math formula. We want to use math calculation to show the sum of user input for the above two fields, so we would edit the custom text field and type in:

`[field4+field8]`

Now click on **Preview** and enter some numbers in the two fields and you would see the calculation take place in real-time.

This is a common format that all math calculations follow in FormCrafts: we enclose the formula in square brackets. Within the brackets, you can use round brackets, and the following operators: **+ - / ***

## Example two

In the previous example, we used direct user input to calculate something. In this example, we will base our calculations based on product selection. Add a **Checkbox** field to your form. Next, edit the **Options List** for this field and use the following three options:

`5==Coffee`

6==Pastry

8==Cake

Note the format. For the first option, **Coffee** is the option text, and **5** is the option value. The string to the left of **==** is always the value, and the string to the right is the text.

Note the field ID for this field: say it is **field9**.

Now, how do we modify the first formula to display the sum of all three fields? Simple:

`[field4+field5+field9]`

If we click on **Preview** we would be able to test our form:

## What is possible with math calculations

As we stated math formulas are contained in square brackets and can use basic operators: **+ - / ***. You can also use round brackets within the formulas. You can also use regular numbers within the formulas. The following are examples of valid math formulas:

`[ (field10 - field 2 - field 1) * field10 ]`

`[field32 + ( field21 * 0.75 )]`

`[field32 + ( (field 1 + field2) / 10 ) ]`

`[ 100 + ( field10 * 0.95 ) ]`

## Where can you use math calculations?

In the above examples we displayed math calculations in a **Custom text** field. You can also use these formulas in:

- Amount part of your Stripe field (which is an excellent way to create dynamic order forms)
- Email subject and body for notification emails
- Email subject and body for autoresponder emails
- The value part of hidden fields
- The 'thank you' message

## Further reading

We recommend reading about form variables, which explains how to reference form values in other parts of the form. Math formulas are built on top of form variables.

Also, check out our tutorial on creating a math quiz.

## Special cases

### Checkbox, Dropdown, Showcase Fields, Star Rating, and Smiley Fields

The options of these fields contain two parts: a value, and a text. There is also an optional third part - image URL. When you edit the field you specify options under Option List, in this format:

Value==Text==Image URL

In this case, the value is **32** and the text is **Chocolate**. The text is shown to the user, while the value is used by the math engine. If you are building a payment form the **value** would be your **price**.

### Datepicker field

With a datepicker field the value is the difference between the selected date, and today. If today is 1-Jan-2020, and the user selects 14-Jan-2020 in the field, the value used by the math engine is 14.

### Fileupload field

For a fileupload field the value used by the math engine is the number of files uploaded.

### Matrix and Tabular fields

These fields are a composite of smaller fields, and don't have one value. They cannot be used in math formulas.