Cognito-forms – Trying to do a calculation with a text field and a number in Cognito Forms

cognito-forms

The problem I'm having is that when an option in a drop-down box is selected, I need the selected option to be entered into a calculation in another field. However, the selected option is a number but due to the selected option from the drop-down box being formatted as "text", it is not allowing me to make the calculation I need in the following field as it needs to be a number format.

Is there a way I can change the selected option from the drop-down into a number in order to enter it into my calculation?

Best Answer

I am a developer for Cognito Forms.

Cognito Forms leverages .Net syntax for it's expression parsing. You would need to use the Int32.Parse or Decimal.Parse methods to convert the text value of the choice field to a number.

For example: If you had a form with 2 fields, one is a Currency field called Unit Price and then a choice field, called Quantity with options 1, 2, 3. You could then add a calculation field to the form with a calculation expression of =Decimal.Parse(Quantity) * UnitPrice