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

# Form calculations and variables

> Calculate prices for order forms, compute the score of a quiz, and much more with your Fillout forms. Dynamic variables let you do math and logic in your form, fully responsive to respondent input.

export const Arcade = ({src}) => {
  const fullSrc = src.startsWith('http') ? src : `https://demo.arcade.software/${src}?embed&embed_mobile=tab&embed_desktop=inline&show_copy_link=true`;
  return <div style={{
    position: "relative",
    paddingBottom: "calc(56.111111% + 41px)",
    height: "0px",
    width: "100%"
  }}>
      <iframe src={fullSrc} title="build.fillout.com" frameBorder="0" loading="lazy" webkitallowfullscreen="true" mozallowfullscreen="true" allowFullScreen allow="clipboard-write" style={{
    position: "absolute",
    top: "0",
    left: "0",
    width: "100%",
    height: "100%",
    colorScheme: "light"
  }} />
    </div>;
};

## Video tutorial

<iframe width="720" height="420" src="https://www.youtube.com/embed/51JXFjaZF6k" title="How to add calculations to your form" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen />

## How it works

Calculations in Fillout forms lets you compute values and respondent input, and display them. They are built using step-by-step rules rather than a single formula.

For example, let’s calculate the total cost of a chicken wings order based on quantity.

## Interactive demo

<Arcade src="b0tHMCx2QSzJjPZvmoSs" />

Each rule performs one operation, and the result is passed to the next rule in sequence.

For example, instead of writing "(A + B) x C" in one line, you would break it down into separate rules:

* Rule 1: Start with A (initial value = @FieldA) and Add @FieldB
* Rule 2: Take the total from Rule 1 and multiply by @FieldC

Each step is processed in order, which ensures the final result is calculated correctly.

When the result is shown in the form, it follows a fixed display format:

* Values are shown up to 2 decimal places
* Trailing zeros are not displayed (e.g. `10.2` not `10.20`)
* No currency symbols or thousands separators are added
* Rounding to whole numbers isn’t supported directly in the form

## Add a calculation

By opening the Logic modal, you can create calculations to compute values dynamically based on static values or previous respondent input. Let's add calculations to an order form.

<Steps>
  <Step title="Open Logic">
    Click the `Logic` modal in the bottom-right of your form editor.

    <img src="https://mintcdn.com/fillout-005a867b/kRBLEIqijamYooVf/images/Screenshot2025-11-25at6.32.40PM.png?fit=max&auto=format&n=kRBLEIqijamYooVf&q=85&s=1d16ea07ad02cae6323cda6a794df0a1" alt="Screenshot 2025-11-25 at 6.32.40 PM.png" width="2638" height="1441" data-path="images/Screenshot2025-11-25at6.32.40PM.png" />

    In the popup, click `Calculations` on top followed by `+ Add new calculation`.

    <img src="https://mintcdn.com/fillout-005a867b/A57fUZPIpaBpeZ-m/images/Screenshot-2026-04-13-at-5.09.06-PM-1.png?fit=max&auto=format&n=A57fUZPIpaBpeZ-m&q=85&s=48dc8d1130be2ce5493c312aeddecb36" alt="Screenshot 2026 04 13 At 5 09 06 PM" title="Screenshot 2026 04 13 At 5 09 06 PM" style={{ width:"48%" }} width="1080" height="519" data-path="images/Screenshot-2026-04-13-at-5.09.06-PM-1.png" />

    Enter a **Name** or label and choose the **Type**, which can be:

    * **Number** - for numerical results like price or score
    * **Text** - for dynamic text based on responses
    * **Duration** - for intervals between dates, like age or term

    For example, let's compute the price for multiple orders of our mozzarella sticks dish. This would use the `number` type.
  </Step>

  <Step title="Enter initial value">
    Type the value you'd like to start with. Some common examples:

    * **0** - to add to a price variable as options are selected
    * **100** - to deduct points from a quiz
    * **Any arbitrary text** - for a **text** calculation, or leave empty

    In our example, we'll start with the quantity. Let's reference this by clicking <Icon icon="square-plus" iconType="solid" /> and selecting the field.

    <img src="https://mintcdn.com/fillout-005a867b/kRBLEIqijamYooVf/images/Screenshot2025-11-25at6.45.52PM.png?fit=max&auto=format&n=kRBLEIqijamYooVf&q=85&s=58ca811fc7880a0fcbb1895cf24af41b" alt="Screenshot 2025-11-25 at 6.45.52 PM.png" width="1392" height="847" data-path="images/Screenshot2025-11-25at6.45.52PM.png" />
  </Step>

  <Step title="Define rules">
    Click `+ New rule` to determine how the initial value will change. A rule is made up of 3 main parts:

    * **Condition** - a parameter, than when true, performs the calculation (e.g. add x amount when a respondents selects "yes" to a previous question)
    * **Operation** - what to do to the calculation (e.g. add, subtract, multiply, divide)
    * **Operation value** - the value used with the operation (e.g. add x amount to your initial value)

    First, click `Set conditional logic` followed by `+ Add condition`. Select the question or field on the left, qualifier in the middle, and choice on the right.

    <img src="https://mintcdn.com/fillout-005a867b/kRBLEIqijamYooVf/images/Screenshot2025-11-25at7.17.23PM.png?fit=max&auto=format&n=kRBLEIqijamYooVf&q=85&s=38e50b8f1c0800287cda74e658861aeb" alt="Screenshot 2025-11-25 at 7.17.23 PM.png" width="1344" height="558" data-path="images/Screenshot2025-11-25at7.17.23PM.png" />

    In our example, we'll choose the "Appetizer" field. The calculation will start when "Mozzarella sticks" is selected. Since we want customers to be able to add other appetizers if they prefer, we'll choose "has any" as the qualifier.

    <img src="https://mintcdn.com/fillout-005a867b/kRBLEIqijamYooVf/images/Screenshot2025-11-25at7.40.27PM.png?fit=max&auto=format&n=kRBLEIqijamYooVf&q=85&s=fcfbef667453c4b278723985f5fdaf31" alt="Screenshot 2025-11-25 at 7.40.27 PM.png" width="1336" height="550" data-path="images/Screenshot2025-11-25at7.40.27PM.png" />

    Our **operation** will be "multiplying" the quantity (initial value) by the price of the dish (**operation value**), which is "\$6".

    <Warning>
      Rules are applied in the order they appear. For example, the first rule adds 5, the second multiplies by 2. To change the order, just drag and drop.
    </Warning>
  </Step>

  <Step title="Test your calculation">
    Exit Logic and click `Preview` on the upper right corner to check that it works as intended.
  </Step>

  <Step title="Publish and share">
    Once everything's set, `Publish` and share or embed your form.
  </Step>
</Steps>

### Rule hierarchy for results

To resolve conflicts between rules, results follow a clear priority order. Higher-priority rules always take precedence over lower-priority ones.

* **A always wins (Highest priority):** All A rules take precedence over every other rule.
* **B always wins after A:** Applies after A. B rules are overridden when they conflict with A.
* **C always wins after B:** Applies after A and B. C rules are overridden when they conflict with A or B.
* **D only wins when the others don't (Lowest priority):** Only applies when none of the higher-priority rules (A, B, or C) apply.

## Dynamic calculation

**Make the price dynamic**

After adding a [payment page](https://www.fillout.com/help/payment-page), type **@** or click <Icon icon="square-plus" iconType="solid" /> and click <Icon icon="calculator" /> to reference a calculation. Now, the price will change depending on the customer's order.

<img src="https://mintcdn.com/fillout-005a867b/zTTJ0plr6uE42LZN/images/Screenshot-2026-04-13-at-5.31.41-PM-1.png?fit=max&auto=format&n=zTTJ0plr6uE42LZN&q=85&s=c622ff5b784535f306f04bde779fea6a" alt="Screenshot 2026 04 13 At 5 31 41 PM" title="Screenshot 2026 04 13 At 5 31 41 PM" style={{ width:"60%" }} width="1348" height="1256" data-path="images/Screenshot-2026-04-13-at-5.31.41-PM-1.png" />

**Display dynamic calculation results in your form**

On a heading or paragraph field, you can type **@** and click <Icon icon="calculator" /> to [reference previous answers or calculations](/answer-piping).

<img src="https://mintcdn.com/fillout-005a867b/zTTJ0plr6uE42LZN/images/Screenshot-2026-04-13-at-5.31.50-PM.png?fit=max&auto=format&n=zTTJ0plr6uE42LZN&q=85&s=0c1a518da1c559ecfb138aa10fd306fd" alt="Screenshot 2026 04 13 At 5 31 50 PM" title="Screenshot 2026 04 13 At 5 31 50 PM" style={{ width:"72%" }} width="2048" height="1242" data-path="images/Screenshot-2026-04-13-at-5.31.50-PM.png" />

You can [style this text](/themes) by highlighting it and changing the font size, weight, or color.

**Pre-fill fields with calculations**

To pipe calculations as input, open the field's settings <Icon icon="gear-complex" iconType="solid" />. Under **Default value**, click <Icon icon="square-plus" iconType="solid" /> followed by <Icon icon="calculator" /> to reference a calculation.

<img src="https://mintcdn.com/fillout-005a867b/n01mkWZYFi5IQJhf/images/Screenshot-2026-04-17-at-7.28.32-PM.png?fit=max&auto=format&n=n01mkWZYFi5IQJhf&q=85&s=f536d425f88bb76582b89ea9bb619def" alt="Screenshot 2026 04 17 At 7 28 32 PM" title="Screenshot 2026 04 17 At 7 28 32 PM" style={{ width:"59%" }} width="1532" height="806" data-path="images/Screenshot-2026-04-17-at-7.28.32-PM.png" />

## Compute duration

Determine age, trip duration, warranty validity, and more with a `duration` calculation. Simply enter a date range.

<img src="https://mintcdn.com/fillout-005a867b/eyFDt8-J2lN7LjRZ/images/logic/image-13.png?fit=max&auto=format&n=eyFDt8-J2lN7LjRZ&q=85&s=f81cfaed835420d4def887cbb9212ccf" alt="Screenshot of the Logic tab of a form" style={{ width:"76%" }} width="1232" height="736" data-path="images/logic/image-13.png" />

## Pre-fill fields with a calculation

Much like how fields are [pre-filled](/prefill-fields) elsewhere in Fillout, you can reference calculations there as well.

## Compute quiz scores

Fillout automatically computes score and lets you [display it on any page](https://www.fillout.com/help/make-a-free-quiz#advanced-quiz-features) you prefer. Additionally, you can [use weighted scoring](https://www.fillout.com/help/make-a-free-quiz#advanced-quiz-features), which also lets you [assign results based on total score](https://www.fillout.com/help/outcome-quiz#assign-results-based-on-total-score).

## Related articles

<CardGroup cols={3}>
  <Card title="Answer piping" color="#FFC738" icon="wand-magic-sparkles" iconType="regular" href="/answer-piping">
    Insert previous answers into upcoming questions or fields.
  </Card>

  <Card title="Pre-fill fields" color="#FFC738" icon="fill" iconType="solid" href="/prefill-fields">
    Pre-populate fields based on previous inputs and more.
  </Card>

  <Card title="Integration logic" color="#FFC738" icon="gear-complex" iconType="regular" href="/conditional-integration">
    Perform an integration only when a certain condition is met.
  </Card>
</CardGroup>
