Skip to main content

Arithmetic Modifiers

Since: 1.4.20

Arithmetic modifiers let you perform basic math operations on numeric values directly within your dynamic data expressions.

Both operands (the value and the argument) must be numeric — either numbers or numeric strings. If either operand is not numeric, or if the argument is missing, the original value is returned unchanged. Numeric strings are trimmed and converted automatically (e.g., " 5 " is treated as 5).

Available Modifiers

ModifierDescriptionExample
.add()

Adds the given value to the current value.
More Details

price = 10

{price.add(5)}15
.subtract()

Subtracts the given value from the current value.
More Details

price = 10

{price.subtract(3)}7
.multiply()

Multiplies the current value by the given value.
More Details

quantity = 4

{quantity.multiply(2.5)}10
.divide()

Divides the current value by the given value. Division by zero returns the original value.
More Details

total = 100

{total.divide(4)}25
.mod()

Returns the remainder after dividing the current value by the given value. Division by zero returns the original value.
More Details

index = 7

{index.mod(3)}1

Detailed Modifier Reference

.add()

Returns: number or original value

The .add() method adds the argument to the current value.

ArgumentTypeDefaultDescription
valuenumberThe value to add

Examples:

  • value = 5
    • {item.value.add(3)}8
  • value = 5.5
    • {item.value.add(3.25)}8.75
  • value = "hello"
    • {item.value.add(3)}"hello" (non-numeric, unchanged)

.subtract()

Returns: number or original value

The .subtract() method subtracts the argument from the current value.

ArgumentTypeDefaultDescription
valuenumberThe value to subtract

Examples:

  • value = 10
    • {item.value.subtract(3)}7
  • value = 5.5
    • {item.value.subtract(3.25)}2.25
  • value = "hello"
    • {item.value.subtract(3)}"hello" (non-numeric, unchanged)

.multiply()

Returns: number or original value

The .multiply() method multiplies the current value by the argument.

ArgumentTypeDefaultDescription
valuenumberThe value to multiply by

Examples:

  • value = 5
    • {item.value.multiply(3)}15
  • value = 3.3
    • {item.value.multiply(2.5)}8.25
  • value = "hello"
    • {item.value.multiply(3)}"hello" (non-numeric, unchanged)

.divide()

Returns: number or original value

The .divide() method divides the current value by the argument. If the divisor is zero, the original value is returned unchanged.

ArgumentTypeDefaultDescription
valuenumberThe value to divide by

Examples:

  • value = 12
    • {item.value.divide(3)}4
  • value = 5.5
    • {item.value.divide(2.5)}2.2
  • value = 10
    • {item.value.divide(0)}10 (division by zero, unchanged)
  • value = "hello"
    • {item.value.divide(3)}"hello" (non-numeric, unchanged)

.mod()

Returns: number or original value

The .mod() method returns the remainder after dividing the current value by the argument. If the divisor is zero, the original value is returned unchanged.

ArgumentTypeDefaultDescription
valuenumberThe value to divide by (divisor)

Examples:

  • value = 7
    • {item.value.mod(3)}1
  • value = 5.5
    • {item.value.mod(2)}1.5
  • value = 10
    • {item.value.mod(0)}10 (division by zero, unchanged)
  • value = "hello"
    • {item.value.mod(3)}"hello" (non-numeric, unchanged)

Example use case: Alternating row styles

Use .mod() to apply alternating CSS classes in a loop:

{#loop items as item, index}
<div class="{index.mod(2).equal(0, 'row--even', 'row--odd')}">
{item.name}
</div>
{/loop}

Combining Arithmetic Modifiers

Like all modifiers, arithmetic modifiers can be chained together or combined with other modifier types:

{item.price.multiply(1.2).round(2).numberFormat(2, ".", ",")}

This multiplies a price by 1.2 (e.g., adding 20% tax), rounds to 2 decimal places, and formats with thousands separators.