Cognito Forms – How to Calculate Average

cognito-forms

I have two input fields with type number A and B. I added A calculation field where I want to show the average of these two input fields. So I typed in =(A + B)/2.

I get an error on this formula saying:

Error at character 0. Type must be decimal.

But I cannot choose for decimal field type in the radio list.

Does anyone have a solution for this?

Best Answer

In cases where the input type cannot be clearly defined but the input is to be treated as a number you can actually force the calculation to evaluate the input as a number.

So in your scenario where you have 2 radio list choices and you want to average the numbers.

Instead of this:

=(A + B)/2

Try this instead:

=(int32.Parse(A)+int32.Parse(B))/2

I did a similar test. Here is the form on the form builder screen with calculated field:

Form Definition

Here is the form itself doing the calculation:

Form with Calculations based on radio boxes