Celebrate WordCamp Europe - 30% OFF! Use coupon WC30 - View Details

Calculated FieldsPRO

The #calc calculated fields function in WS Form PRO makes it easy to create calculate field values that are updated in realtime. It can handle everything from simple addition to more complex trigonometric functions.



How To Create A Calculated Field

Common field types you might use a calculated field in include:

You can put calculated values in the following settings of a field:

  • Label
  • Default value
  • Content (Text Editor / HTML fields)
  • Placeholder
  • Help
  • Minimum
  • Maximum

To create a calculated field value for the default value of a field, click the field settings icon and then enter a #calc(...) variable in the Default Value setting.

WS Form - Calculated Field Values - Default Value Setting

Anything within the brackets will be calculated in realtime on your form and used as the value of your field.

You can create calculations such as:

#calc(1 + 2)

You can include values from other fields on your form, for example, multiplying field ID 123 value by 5:

#calc(#field(123) * 5)

You can use WS Form math variables (listed at the end of this document) to perform more complex calculations, for example, rounding the previous example to two decimal places:

#calc(#round(#field(123) * 5, 2))

You could even create a calculated field that works out the sum of all values of a field in a repeatable section. The syntax is easy:


… where field ID 123 is a field in a repeatable section. WS Form PRO automatically sums the values together.  The #section_row_count(456) function (where 456 is the section ID) can be used to calculate the average value of those values:

#calc(#field(123) / #section_row_count(456))

There is an easier way of creating these calculations … the calculator!


WS Form PRO includes a calculator feature that helps creating calculated values for fields.

  1. Click the field settings icon.
  2. Click the calculator icon. On most fields this is found on the Default Value setting.

The calculator will then appear directly below:

WS Form PRO - Calculated Fields - Calculator

The cursor will automatically position itself within the #calc() function. In addition to the normal numeric and arithmetic buttons, the calculator has the following additional buttons:

Insert Field – Click this to insert a #field() variable into your calculated field. It lists all of the fields on your form that are compatible with the calculated field feature.

del – Deletes a character

AC (All Clear) – Deletes the entire calculation

f – Inserts a math variable into your calculation such as #pi, #cos(...) or #sin(...) (See below)

Note that whilst the calculator will do its best to maintain a suitable cursor position, you can always click on the default value itself to reposition the cursor.

Source Field Rules

If a field used in a calculation is an e-commerce type (e.g. price, price select etc), the input value is assumed to be a currency and WS Form will therefore correctly interpret the price according to your currency symbol, decimal and thousand separator settings and will convert that to a floating point number.

If a field used in a calculation is not an e-commerce type (e.g. number, text, select etc), the input value should follow standard conventions used for evaluating numbers in JavaScript, i.e.

  • Period for decimal separator
  • No thousand separators

For example: 123.45

Display Calculations as Prices

If you wish to show a calculation as a price using your currency settings, you can use the ecommerce_price variable, for example:

#ecommerce_price(#calc(#field(1) + #field(2)))

JavaScript Floating Point Rounding

WS Form calculations are assessed using standard JavaScript. In some cases this can result in floating point numbers such as:

123.40000000000001 instead of 123.4

This is actually perfectly normal in the computing world! If you’re interested here is an explanation.

In order to get a neater looking number, simply use the #round variable, for example:

#round(#calc(#field(1) + #field(2)), 1)

The last parameter is the number of decimal places you would like to use.


In addition to #field(...), the following variables can be used inside with #calc(...).


Name / VariableAdditional Information
Returns the absolute value of a number.
Returns the average of all the input numbers.
Base to the Exponent Power
#pow(base, exponent)
Returns the base to the exponent power.
Rounds a number up to the next largest whole number.
Returns the cosine of a radian number.
Returns E to the power of a number.
Returns the largest integer value that is less than or equal to a number.
Inverse Cosine
Returns the inverse cosine of a number in radians.
Inverse Sine
Returns the inverse sine of a number in radians.
Inverse Tangent
Returns the inverse tangent of a number in radians.
Returns the natural logarithm of a number.
Returns the maxiumum value of the supplied numbers.
Returns the lowest value of the supplied numbers.
Returns 0 if positive, or original value if negative.
Returns an approximate value of PI.
Returns 0 if negative, or original value if positive.
#round(number, decimals)
Returns the rounded value of a number.
Returns the sine of a radian number.
Square Root
Returns the square root of the number.
Returns the tangent of a radian number.


Name / VariableAdditional Information
Format Number
#number_format(number, decimals, decimal_separator, thousand_separator)
Returns a number with grouped thousands. Same as the PHP number_format function.

Random Numbers

Name / VariableAdditional Information
Random Number
#random_number(min, max)
Outputs an integer between the specified minimum and maximum attributes. This function does not generate cryptographically secure values, and should not be used for cryptographic purposes.


Name / VariableAdditional Information
Seconds in a day
Returns the number of seconds in a day.
Seconds in a minute
Returns the number of seconds in a minute.
Seconds in a week
Returns the number of seconds in a week.
Seconds in a year
Returns the number of seconds in a common year.
Seconds in an hour
Returns the number of seconds in an hour.
Seconds since Epoch
Returns the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
Seconds since Epoch at midnight
Returns the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) to the closest previous midnight. This variable can only be used in client-side.