Cognito Forms logo

Numeric calculations

Cognito Forms makes it easy to write calculations that work with numbers. Start by using the appropriate field types to represent numbers: including Number, Currency, and Calculation (Number, Percent & Currency) fields.

1. Syntax

2. Functions


Syntax

For example, say you have two Number fields on your form, Adults and Children, representing the number of adults and children registering for an event. You could add a Calculation field that shows the total number of people attending the event, using the simple calculation  =Adults + Children.

Now, on your form, you can see this calculation in action:

Here are examples of basic numeric calculations you could perform with these fields:

Type

Example

Results for 2 Adults and 3 Children

Addition

=Adults + Children

2 + 3 = 5

Subtraction

=Adults - Children

2 - 3 = -1

Multiplication

=Adults * Children

2 * 3 = 6

Division

=Adults / Children

2 / 3 = 0.66667

Equals

=Adults = Children, or
=Adults == Children

2 = 3 = false

Not Equals

=Adults != Children, or
=Adults <> Children

2 != 3 = true

Greater Than

=Adults > Children

2 > 3 = false

Greater Than or Equals

=Adults >= Children

2 >= 3 = false

Less Than

=Adults < Children

2 < 3 = true

Less Than or Equals

=Adults <= Children

2 <= 3 = true

 

When performing basic mathematical calculations, Cognito will treat blank values as zeros, so for example, 2 + blank would equal 2, and 2 > blank would equal true.

Additionally, you can perform more complex mathematical calculations by calling functions starting with Math, including important functions like Min, Max, Ceiling, Floor and Round. For example, you could write the calculation  = Math.Max(Adults, Children) to calculate the maximum of these two values.

Functions

Here is a full list of supported math functions, which all return numbers:

Function

Description

Math.Abs(Number)

Returns the absolute value of the specified number.

Math.Acos(Number)

Returns the angle whose cosine is the specified number.

Math.Asin(Number)

Returns the angle whose sine is the specified number.

Math.Atan(Number)

Returns the angle whose tangent is the specified number.

Math.Atan2(Number, Number)

Returns the angle whose tangent is the quotient of the specified numbers.

Math.Ceiling(Number)

Returns the smallest integer value that is greater than or equal to the specified number.

Math.Cos(Number)

Returns the cosine of the specified angle.

Math.Cosh(Number)

Returns the hyperbolic cosine of the specified angle.

Math.E

Returns the natural logarithmic base.

Math.Exp(Number)

Returns e raised to the specified power.

Math.Floor(Number)

Returns the largest integer value that is less than or equal to the specified number.  (Round down)

Math.Log(Number)

Returns the natural logarithm of the specified number.

Math.Log(Number, Number)

Returns the logarithm of arg1 in the base arg2.  i.e. Log(num, base)

Math.Log10(Number)

Returns the base 10 logarithm of the specified number.

Math.Max(Number, Number)

Returns the larger of the two specified numbers.

Math.Min(Number, Number)

Returns the smaller of the two specified numbers.

Math.PI

Returns the ratio of the circumference of a circle to its diameter.

Math.Pow(Number, Number)

Returns the number arg1 raised to the power arg2.  i.e. Pow(num, power)

Math.Round(Number)

Returns the nearest integer value.

Math.Round(Number, Number)

Returns a decimal value to a specified number of fractional digits.  We currently only support displaying up to 2 fractional digits.  i.e. Round(num, fracDigits)

Math.Sign(Number)

Returns a value representing the sign of the specified number.  Returns -1, 0, or 1 which means the number is negative, 0, or positive, respectively.

Math.Sin(Number)

Returns the sine of the specified angle.

Math.Sinh(Number)

Returns the hyperbolic sine of the specified angle.

Math.Sqrt(Number)

Returns the square root of the specified number.

Math.Tan(Number)

Returns the tangent of the specified angle.

Math.Tanh(Number)

Returns the hyperbolic tangent of the specified angle.

Math.Truncate(Number)

Returns the integral part of the specified number.

Printable View