Skip to main content
penscript supports arithmetic, number formatting, and numeric comparisons. These operators are used in computed form fields, premium calculations, validation rules, and automation conditions.

Addition: :sum

Returns the sum of all numbers in a list.
{ ":sum": [11, 5, 6, -2] }
// Result: 20
Works with variables:
{ ":sum": ["{data.amount_1}", "{data.amount_2}", "{data.amount_3}"] }

// Scope: { "data": { "amount_1": 100, "amount_2": 250, "amount_3": 50 } }
// Result: 400
Also used for date arithmetic — see the Dates & time page for details.

Multiplication: :multiply

Multiplies two values together.
{ ":multiply": [5, 3] }
// Result: 15

{ ":multiply": ["{data.quantity}", "{data.unit_price}"] }
// Scope: { "data": { "quantity": 4, "unit_price": 25 } }
// Result: 100
Commonly used inside :pipe for sequential transformations:
{ ":multiply": ["@value", 2] }
// Result: double the current @value

Product / Decimal Formatting: :product

Converts a number to a string with a specified number of decimal places.
{ ":product": [3.14159, 2] }
// Result: "3.14"

{ ":product": [0.7355, "{data.horses_power}"] }
// Scope: { "data": { "horses_power": 110 } }
// Result: "80.91"
The first argument is the value, the second is the number of decimals to keep. The result is always a string.

Division: :divide

Divides the first number by the second.
{ ":divide": [100, 4] }
// Result: 25

{ ":divide": ["{data.total}", "{data.count}"] }
// Scope: { "data": { "total": 750, "count": 3 } }
// Result: 250

Power: :power

Raises a base to an exponent.
{ ":power": [2, 3] }
// Result: 8

{ ":power": [10, 2] }
// Result: 100

Min / Max: :min, :max

Returns the lowest or highest value from an array.
{ ":max": [3, 7, 2, 9, 1] }
// Result: 9

{ ":min": [3, 7, 2, 9, 1] }
// Result: 1
Works with variables:
{ ":max": ["{data.offer_a}", "{data.offer_b}", "{data.offer_c}"] }

Number Formatting: :format-number

Formats a number for display. Use :digits to control decimal precision.
{
  ":digits": 0,
  ":format-number": {
    ":product": [0.7355, "{data.horses_power}"]
  }
}

// Scope: { "data": { "horses_power": 110 } }
// Result: 81
{
  ":digits": 2,
  ":format-number": { ":sum": ["{data.subtotal}", "{data.tax}"] }
}

// Scope: { "data": { "subtotal": 99.5, "tax": 20.895 } }
// Result: 120.40

Age Calculation: :age

Calculates age in years from a date value. Typically used as an inline pipe (see Dates & time for the full reference), but also available as an operator in numeric contexts.
"{data.birthdate | age}"
// → 34

{
  ":cmp": "{data.birthdate | age}",
  ":gte": 18
}
// → true if the person is 18 or older

Numeric Comparisons

Use :cmp with numeric values for conditional logic based on calculations:
{
  ":if": { ":cmp": "{data.price}", ":gte": 100 },
  ":then": "Premium tier",
  ":else": "Standard tier"
}

// Scope: { "data": { "price": 110 } }
// Result: "Premium tier"
Combining arithmetic with comparison:
{
  ":if": {
    ":cmp": { ":sum": ["{data.deductible}", "{data.premium}"] },
    ":gt": 10000
  },
  ":then": "Requires approval",
  ":else": "Auto-approved"
}

Next Steps