> ## Documentation Index
> Fetch the complete documentation index at: https://help.hoopai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Math calculations in forms

> How to use calculated fields in HoopAI forms — arithmetic, field references, conditional calculations, and use cases.

Calculated fields in HoopAI forms let you perform math operations based on user input — perfect for price calculators, ROI tools, BMI calculators, and quoting engines.

***

## Adding a calculated field

<Steps>
  <Step title="Open the form builder">
    Go to **Sites → Forms & Surveys** and create or edit a form.
  </Step>

  <Step title="Add input fields">
    Add the fields that will feed into your calculation (Number fields, Dropdown fields with numeric values, etc.).
  </Step>

  <Step title="Add a calculated field">
    Drag a **Calculation** or **Computed** element onto the form. This field displays the result of a formula.
  </Step>

  <Step title="Write the formula">
    In the calculated field settings, write your formula referencing other fields by their field ID.
  </Step>
</Steps>

***

## Basic arithmetic

| Operation      | Syntax                          | Example                                  |
| -------------- | ------------------------------- | ---------------------------------------- |
| Addition       | `field_1 + field_2`             | Total price = base + shipping            |
| Subtraction    | `field_1 - field_2`             | Discount = price - savings               |
| Multiplication | `field_1 * field_2`             | Total = quantity \* unit\_price          |
| Division       | `field_1 / field_2`             | Per-unit cost = total / quantity         |
| Parentheses    | `(field_1 + field_2) * field_3` | Group operations for order of precedence |
| Constants      | `field_1 * 0.08`                | Tax = subtotal \* 8%                     |

***

## Referencing other fields

Use the field's **ID** (not the label) in your formulas. Find the field ID in the field's settings panel.

Example: If you have a Number field with ID `quantity` and another with ID `unit_price`:

```
quantity * unit_price
```

The calculated field updates in real time as the user types.

***

## Conditional calculations

Use conditional logic to apply different formulas based on user selections:

### Example: Tiered pricing

If a dropdown field `plan_type` has values "Basic", "Pro", and "Enterprise":

* Basic: \$29/mo
* Pro: \$79/mo
* Enterprise: \$199/mo

Set up the dropdown with numeric values assigned to each option, then multiply by the quantity or duration field.

### Example: Discount tiers

Apply different discount rates based on quantity:

* 1–10 units: no discount
* 11–50 units: 10% discount
* 51+ units: 20% discount

Use conditional visibility on multiple calculated fields, or use the form's conditional logic to show different results.

***

## Displaying results

| Display option    | How                                                        |
| ----------------- | ---------------------------------------------------------- |
| **As a number**   | The raw calculated value                                   |
| **As currency**   | Format with \$ prefix and 2 decimal places                 |
| **As percentage** | Format with % suffix                                       |
| **Hidden**        | Calculate but do not show (useful for intermediate values) |

Configure the display format in the calculated field's settings.

***

## Use cases

<Tabs>
  <Tab title="Price calculator">
    **Fields**: Product dropdown, Quantity (number), Add-ons (checkboxes)

    **Formula**: `(product_price * quantity) + addon_total`

    Shows the total cost in real time as the customer builds their order.
  </Tab>

  <Tab title="ROI calculator">
    **Fields**: Current monthly spend (number), Expected improvement % (slider)

    **Formula**: `monthly_spend * (improvement_pct / 100) * 12`

    Shows projected annual savings.
  </Tab>

  <Tab title="BMI calculator">
    **Fields**: Weight in lbs (number), Height in inches (number)

    **Formula**: `(weight / (height * height)) * 703`

    Displays the BMI result.
  </Tab>

  <Tab title="Loan estimator">
    **Fields**: Loan amount (number), Interest rate (number), Term in months (number)

    **Formula**: Monthly payment calculation using the standard amortization formula.
  </Tab>

  <Tab title="Service quote">
    **Fields**: Hours needed (number), Service level (dropdown with hourly rates), Rush fee (checkbox)

    **Formula**: `hours * hourly_rate * (rush_fee ? 1.5 : 1)`

    Generates an instant quote.
  </Tab>
</Tabs>

***

## Limitations

* Calculated fields are computed client-side (in the browser) and update in real time
* Complex multi-step formulas may need to be broken into intermediate calculated fields
* Trigonometric and advanced math functions may not be available — use basic arithmetic
* Calculated field values can be submitted with the form and stored as contact custom field values
* Precision is limited to standard floating-point arithmetic (minor rounding differences possible)

<Tip>
  For complex calculations that exceed the built-in formula capabilities, use a custom JavaScript snippet in the form's custom code section.
</Tip>

***

## Tips

<AccordionGroup>
  <Accordion title="Show the calculation step by step">
    Use multiple calculated fields to show subtotal, tax, discount, and total separately. This builds trust and transparency.
  </Accordion>

  <Accordion title="Use hidden fields for intermediate values">
    If your formula is complex, break it into smaller calculations using hidden calculated fields, then reference them in the final visible result.
  </Accordion>

  <Accordion title="Test with edge cases">
    Enter zero, very large numbers, and negative numbers to make sure your formula handles them correctly.
  </Accordion>
</AccordionGroup>
