# How to Use Math Logic

## What is Math Logic?

Math logic is used to dynamicaly do calculations based on user input. For example: If you need to add up the value of 2 fields you will use math logic. ## Math Logic with Text Fields

In this example you already added 2 fields called "Value 1" and "Value 2" like in the graphic above.

1. Add a Math Logic field to your form. 2. Edit the field (hover over the field and click on the icon).
3. Click on the "Math Logic" tab on the field's settings Now you will see a list of the current fields in your form and a field where you can add your math equation. 1. Click on Value 1. It will be added to your formula NOTE: If you have a field called "Number of Units" the field's math value place holder will be {number_of_units}
2. Add a plus sign as we want to add these 2 field's value's. 3. Click on Value 2. It will be added to your formula 4. Lets give this Result 2 decimal places. 5. Now go back to your field's input settings to setup where to display the result.
6. Add the math result placeholder "{math_result}" anywhere you need the calculation to be displayed. or anything, like: 7. Done...hit preview and see the math result spin to its calculated value. ## Math Logic with Radio buttons & Check Boxes

In this example we will add a check box field and a radio button field to be multiplied.

The fisrt thing you need to know is how to create vlaues for your check and radios to be different from the labels. For math logic these need to always be numeric!
1. Add a check box field to your form and call it "Products" 2. Click on the Field Input tab and add 3 options - Product A, Product B and Product C 3. Now lets give Product A a value 100, Product B a value of 200 and Product C a value of 300. We do this by using the double equal (==). So its value==label. in this case we will have:

100==Product A
200==Product B
300==Product C  5. Click on the Input tab and add 3 options - One, Two and Three 6. Now lets give One a numeric value of 1, Two a numeric value of 2 and Three a numeric value of 3. We do this by using the double equal (==). So its value==label. in this case we will have:

1==One
2==Two
3==Three  8. Click on the "Math Logic" tab on the field's settings  10. Add a multiply (which is an asterisk (*)) sign as we want to multiply these 2 field's value's. 11. Click on Products[] (the [] are there becouse is a multiple choose selection field). It will be added to your formula 12. Now go back to your field's input settings to setup where to display the result.
13. Add the math result placeholder "{math_result}" anywhere you need the calculation to be displayed. or anything, like: 14. Done...hit preview and see the math result spin to its calculated value. 15. Product A is 100 and Product B is 200 and we multiply it in the above graphic by 2 which equals 600.

## Math Logic with Selects & Multi-selects

In this example we will add a 2 select fields to be devided.

1. Add a select to your form and call it "Loan Amount" 2. Click on the Input tab and add 5 amounts: 1000, 5000, 10000, 50000, 100000.

NOTE: Because our values are already numeric we dont have to use a double equal to specify values different from the labels. So in this case the label(displayd option) and the value is the same. So we just list the values. 3. Add another select field to your form and call it "Loan Term" 4. Click on the Input tab and add 4 loan terms and call then 3 Months, 6 Months, 1 Year, 2 Years 5. Now lets give 3 Months a numeric value of 3, 6 Months a numeric value of 6, 1 Year a numeric value of 12 and 2 Years a numeric value of 24. We do this by using the double equal (==). So its value==label. in this case we will have:

3==3 Months
6==6 Months
12==1 Year
24==2 Years  7. Click on "Loan Amount" from the select dropdown called form fields. It will be added to your formula 8. Add a division (which is a forward slash (/)) sign as we want to devide these 2 field's value's. 9. Click on "Loan Term" from the select dropdown called form fields. It will be added to your formula 10. Now go back to your field's input settings to setup where to display the result.
11. Add the math result placeholder "{math_result}" anywhere you need the calculation to be displayed. For this example we will use "Your monthly installment will be \${math_result} without interest": 12. Done...hit preview and see the math result spin to its calculated value. ## Using caculated totals in other equations

In this example we will use the form we created in the Math Logic and Selects above. We will add a new math logic field to use the calculated total of the one already added and then add 15% interest to it.
Please note that we are not teaching math but simply demonstrating NEX-Forms abilities. So the formulas might not make sense to actual mathematicians ;) . VERY IMPORTANT: Your math result is stored by default into a hidden field called math_result. If this field name is not changed to something else you can not re-use it and it wont be emailed! So if you need to re-use totals performed by other equations in new equations or you need the calculated value to be emailed to you then you need to change the "Math Result Name" to something relevant like for example total_1, formula_1 or whaever is relevant to the equation In this example we will name this math eqaution's result to be: installment_before_interest  2. Click on the "Math Logic" tab on the field's settings
3. We know we called the previous math result installment_before_interest so we know that the we need to use it in an eqaution like this: {installment_before_interest}. Add {installment_before_interest} to the Math Equation 4. Complete the formula: {installment_before_interest} + ({installment_before_interest}*15)/100 5. Now go back to your field's input settings to setup where to display the result.
6. Add the math result placeholder "{math_result}" anywhere you need the calculation to be displayed. For this example we will use "Installment with 15% interest = \${math_result}": 7. Done...hit preview and see the math result spin to its calculated value. REMEMBER: Rename your math result fields to be re-used and/or to send it in your emails.