## Save Computed Data

**Weighting Responses**

When setting up an interactive experience like a quiz, you may want to tell visitors how many correct answers they received once they complete the quiz. To do so, you may use the “Save computed data” action to add a point for every time someone gives the correct answer.

You will find an example of this rule within the Template: Quiz > **CLOUD: 3 Quizzes with Grades**.

On the Results page > Page rules of this experience, behind each correct answer, you will find a rule that adds points to the “Score1” field. You may use the plus sign with the Save computed into database action to add a point to a given field whenever a correct answer is given.

**Advanced Calculations**

The “Save computed data” rule can also be used to perform more advanced calculations. This action will be particularly handy for any experience where you may want to provide visitors with a price or other numeric value based on a response they give in your form.

For example, if you would like to provide visitors with a total price of widgets, you can add a field to your Ion form which asks the visitor how many widgets they are interested in purchasing. You could then apply a rule to your form to calculate the total.

Let’s say each widget costs $25. Let’s also say that the field used in the form for visitors to enter the number of widgets is called “Units.” You may apply a rule that looks like the one below to your form to calculate how much the total order would cost. In our example, we are saving the total cost into a “Total” data field. The “Units” field is added to the rule to dynamically use whatever value the respondent entered for the “Units” field in the live experience.

Content variables can then be used on the Thank You page to display the total cost of the order. To do so, simply type {% raw %}${{Total}}{% endraw %} on the Thank You page. When viewing the page live, {% raw %}{{Total}}{% endraw %} will be replaced with the actual cost that is calculated through this advanced rule.

***NOTE:** You may set up more complex calculations than these examples. Please feel free to utilize parentheses to group operations and multiple content variables throughout the formula to perform more advanced calculations.

## Save Formatted Numeric Data

For example, you may want to set up a calculator experience that shows visitors how much something would cost after sales tax is applied to it. If you want to do this for a specific state, you could fix the sales tax percentage and set up a calculation rule on your form

Let’s say our form is set up with a data field in it called “Price.” Let’s also use 6% for sales tax. You could add a rule to your form that would look like the below to multiply the price by 1.06 (1.06*{% raw %}{{Price}} {% endraw %}) to find the total which would be saved into a data field called “Total.”

In this example, the total often times would have more than two digits to the right of the decimal and would not include any commas when something is more than $999.

The “Save formatted numeric data” action can be used to include commas and to ensure only two digits are present to the right of the decimal point. This action can be added to the original rule as seen below.

In this example, the Save formatted numeric data action will take the total that was calculated in the action above it and ensure that it only has two digits to the right of the decimal. If more than two digits are returned from the calculation, this action will truncate the decimal to only include two digits and will round up or down based on the third digit to the right of the decimal. This action will also add a comma for every three digits to the left of the decimal (i.e. 1,000) and will save a dollar sign in front of the total.

If you would like to format a dollar amount without decimals, you could use the {% raw %}${0:0,0}{% endraw %} format.

If someone were to enter 1523.73 into the form field, the total price with sales tax that would be saved would be $1,615.15 as opposed to 1615.1538. You could also display this total on your Thank You page using dynamic content insertion.

For more information on the types of custom numeric formats that are available, click here .

**Standard Numeric Formats**

There are also more standardized formats that can be set up with the format numeric data action. For example, if you want to set up an experience that could convert a percentage that is calculated and format it accordingly, you could use the {% raw %}{0:p}{% endraw %} format. Please note that for this rule would be based on the premise that we have a percentage already saved to the “Percent” field and we want to format it accordingly.

- Also check our support article: Save computed data for more information on setting up rules to calculate values in Ion.
- To understand standard numeric formats that are available, click here .

If you have any questions, please contact us on [email protected].