Formidable Pro makes it easy to perform calculations using values entered in your form. You may perform basic numeric calculations, separate value numeric calculations, or text calculations in a calculated fields form.

### Numeric calculations

If you would like to perform a calculation where the numeric value used in a calculation fields form can be seen by the user, follow the directions below.

- Go into edit your form.
- Add a
**Number**field to calculate the total. Set it to 'Read Only' if you would like users to see, but not edit, the total.

If you do not want users to see the total, set the Visibility to 'Administrator'. - In the Advanced section for the total field, select the calculator icon in the
**Default Value**section and click the menu icon to open up the**Calculate the Default Value**settings.

- Use the
**Field List**search box to find the fields that you want to include in your calculation. You can use the field ID or key synonymously in a calculation. Your calculation might look something like: [25]+[26]+[27] or ([25]*8)+([27]/2). In the example below, two Number fields are multiplied:

- Enter the number of
**decimal places**for your total. - The total will be updated each time a field that is used in your calculation is changed.

You can use the total field value in your success message, email, or View. If you would like your users to make a payment with this total, you can pass the total amount to Paypal or Stripe.

### Separate value calculations

Follow the directions below if you would like to perform a calculation where the value used in a calculation is not seen by the user. For example, if you have a radio button field with two options (Gold, Silver), then the text must be converted to numbers before calculating the total.

- Go into edit your form.
- Check
**Use separate values**for each field that will be used in your calculation (this can be found in the Field Options for Dropdown, Radio Button, and Checkbox fields).

- Add the number that will be used in your calculation to the end of each saved value. The calculation will only use numbers and decimals from the end of each saved value. Any other text or numbers before this will be ignored.

*Please note that the saved value***cannot**be identical to any other saved value. If you have saved values that must have the same numeric value, they need to be entered like this: Gold - $25.00, Silver - $25.00. - Add a
**Number**field to calculate the total. Set it to 'Read Only' if you would like users to see, but not edit, the total.

If you do not want users to see the total at all, set the Visibility to 'Administrator'. - In the field options, select the calculator icon in the
**Default Value**section. Click the menu icon to open up the**Calculate the Default Value**settings.

- Use the
**Field List**search box to find the fields you want to include in your calculation. You can use the field ID or key synonymously in a calculation. Your calculation might look something like: [25]+[26]+[27] or ([25]*8)+([27]/2). In the example below, we are simply adding two fields together:

- Enter the number of
**decimal places**for your total. - The total will be updated each time a field that is used in your calculation is changed.

### Text calculations

If you would like to combine text from multiple fields into a single field in your form, you may use Formidable's text calculations. Follow the directions below to concatenate multiple field values into a text field.

- Go into edit your form.
- Add a
**Single Line Text**field to your form. This field will contain the combined text. - Expand the Advanced field options and select the calculator icon in the
**Default Value**section. Click the menu icon to open up the**Calculate the Default Value**settings and select**Text**in the toggle.

- Use the
**Field List**search box to find the fields that you want to include in your calculation. You can use the field ID or key synonymously in a calculation. Any spaces or characters used in this box will show in the final value.

- Save your form and preview it. The value will be updated each time a field that is used in your calculation is changed.

### Calculate a user's age

If you would like to calculate a user's age (in years) when they enter their date of birth, follow the instructions below.

- Add a
**Date**field to your form. This will be the 'Date of birth' field. - Add a
**Number**field to your form and title it 'Age'. This is the field where the age will be calculated.- If you want the user to see the age, select 'Read Only'.

If you do not want the user to see the 'Age' field, then set the field Visibility to 'Administrator'. - In the field options, select the calculator icon in the
**Default Value**section. Insert this calculation into the box:[age id=25]

Replace '25' with the ID or key of your 'Date of birth' field.

- If you want the user to see the age, select 'Read Only'.
- Now when the user inserts their birthday, the age will show up in the 'Age' field.

**Note**: Make sure nothing is entered in the "*decimal places*" area in Field Calculations when calculating an age.

If you would like to show the current age in a View, use the date field instead of a calculation so it will always be up to date. Follow the instructions on how to show an age in real time.

### Calculate number of days between two dates

If you would like to calculate the number of days between two dates, follow the instructions below.

- Add a
**Date**field to your form and title it 'Date 1'. Go to Field settings → Field Key and set the value to 'date1'. This will be your starting date field.

- Add another
**Date**field to your form and title it 'Date 2'. Go to Field settings → Field Key and set the value to 'date2'. This will be your end date field.

- Add a
**Number**field to your form and title it 'Number of Days'. This is the field where the number of days will be calculated.- If you want the user to see the 'Number of Days' field, select
**Read Only**.

If you do not want the user to see the 'Number of Days' field, set the field**Visibility**to 'Administrator' in your field settings.

- In the field options, select the calculator icon in the
**Default Value**section. Insert this calculation into the default value box:[date2]-[date1]

Or you could use the

**Field List**search box to find the fields to include in your calculation. Click the menu icon to open up the**Calculate the Default Value**settings. You can use the field ID or key synonymously in a calculation.

- If you want the user to see the 'Number of Days' field, select
- As a result, when the user selects their chosen dates, the number of days between those two dates will be displayed in the 'Number of Days' field.

### Get the total of the values of a Repeater

If you are using calculations in a repeater, follow the instructions on how to get the total of the values in a field in a repeater.

### Unique field combination

Do you need the combination of two fields to be unique? There is a custom code route, but it's possible you may be able to do this without custom code.

- Add a hidden field to your form.
- Check the 'Unique' box and customize the unique error message for this field.
- In the field options, select the calculator icon in the
**Default Value**section. Click the menu icon to open up the**Calculate the Default Value**settings and select**Text**in the toggle. - Insert a calculation that includes the two fields. So if you are limiting the form to one user per date, include the user ID and date fields in the calculation. It would work the best to include a dash between the two field values like [25]-[26].
- This will work best if both of the fields used in the calculation are required. Now when a logged in user tries to select and submit a date they already submitted, your unique message for the hidden field will be displayed.

#### Number Format

- If you would like to round your total to two decimal places, enter
**2**in the 'decimal places' box. - If you would like to round your total to the nearest whole number, enter
**0**in the 'decimal places' box. - If you would like to add two decimal places in a single field by default, enter
**2**in the 'decimal places' box and**[x]**in the calculations box (where**x**is the field ID/key). - If you would like to round a number down to its nearest integer, add
**Math.floor**to the beginning of your calculation.Math.floor([25]+[26]+[27])

- If you would like to add a dollar sign in front of your number, go into your form and click on 'Settings' → 'Customize HTML'. Find the box that corresponds to the field holding the number. Put a dollar sign in front of [input].

If the dollar sign appears above the field, you need to decrease the field size.

### Conditional calculations

You can use the ternary operator in field calculations if you need to base your desired calculation off of another field value.

#### Syntax

Condition ? True : False

True/False can be individual calculations, or can be standalone values. Condition should be a less than, greater than, or equal to comparison, or a combination of these comparisons.

#### Example

Consider the example below:

([15] > 500) ? ([15] * .02) : (10)

This calculation is entirely valid, and is saying *IF field ID 15 is greater than 500, calculate the value of field ID 15 multiplied by .02, or 2%. ELSE add a flat value of 10.* This is one way to use a conditional calculation—calculate a flat rate below a certain price, or a percent rate above that price.

Extending this example we can create multiple conditions:

([15] > 500 || [15] < 50) ? ([15] * .02) : (10)

Now, if field ID is less than 50, a percentage rate will also be charged, rather than a flat rate of 10.

### Advanced numeric calculations

- If you would like to add exponents to an equation, you can use
**Math.pow**:Math.pow([x],2)

Replace x with a field ID for the base and replace 2 with the exponent amount.

- For more advanced calculations, such as minimums, maximums, and square roots, see the JavaScript Math object.

### Calculation demo

Click here to see a calculations demo.