Skip to main content
Math helpers perform arithmetic operations on numbers.

add

Adds two numbers.
Output: 15

subtract

Subtracts the second number from the first.
Output: 7

multiply

Multiplies two numbers.
Output: 50

divide

Divides the first number by the second.
Output: 5
Division by zero returns 0 to prevent errors.

modulo

Returns the remainder of division.
Output: 2 Use cases:
  • Alternating row colors
  • Checking even/odd

power

Raises a number to a power.
Output: 8

sqrt

Returns the square root of a number.
Output: 4

round

Rounds a number to specified decimal places.
Examples:

ceil

Rounds up to the nearest integer.
Output: 4 Use cases:
  • Page counts
  • Minimum quantities

floor

Rounds down to the nearest integer.
Output: 3

abs

Returns the absolute value.
Output: 42 Use cases:
  • Displaying differences
  • Ensuring positive values

random

Generates a random number between min and max.
Random values change on each render. Use carefully in templates where consistency matters.

Combining Math Helpers

Calculate Line Total

Calculate Discount

Calculate Tax

Calculate Grand Total

Average Price

Practical Examples

Invoice Calculations

Progress Percentage

Pagination