Calculations & Functions

Zolt features a robust expression engine for performing calculations and manipulating data.

Calculations

Basic Math

zolt
+ $10 + 5 = {{ 10 + 5 }}$
+ $20 - 8 = {{ 20 - 8 }}$
+ $3 * 4 = {{ 3 * 4 }}$
+ $15 / 3 = {{ 15 / 3 }}$
+ $10 \% 3 = {{ 10 % 3 }}$
+ $2 ^ 8 = {{ 2 ^ 8 }}$
Result
  • 10+5=1510 + 5 = 15
  • 208=1220 - 8 = 12
  • 34=123 * 4 = 12
  • 15/3=515 / 3 = 5
  • 10%3=110 \% 3 = 1
  • 28=2562 ^ 8 = 256

Operator Precedence

zolt
+ $3 + 2 * 5 = {{ 3 + 2 * 5 }}$
+ $(3 + 2) * 5 = {{ (3 + 2) * 5 }}$
+ $2 ^ {3 ^ 2} = {{ 2 ^ 3 ^ 2 }}$
Result
  • 3+25=133 + 2 * 5 = 13
  • (3+2)5=25(3 + 2) * 5 = 25
  • 232=5122 ^ {3 ^ 2} = 512

Namespace Functions

Math Namespace

The Math namespace provides common mathematical constants and functions.

FunctionArgumentsReturnDescription
Math.floor(n)n: numbernumberReturns the largest integer less than or equal to n.
Math.ceil(n)n: numbernumberReturns the smallest integer greater than or equal to n.
Math.round(n)n: numbernumberReturns the value of n rounded to the nearest integer.
Math.abs(n)n: numbernumberReturns the absolute value of n.
Math.pow(b, e)b: number, e: numbernumberReturns the base b to the exponent e power.
Math.sqrt(n)n: numbernumberReturns the square root of n.
Math.min(...n)...n: numbernumberReturns the smallest of zero or more numbers.
Math.max(...n)...n: numbernumberReturns the largest of zero or more numbers.

Examples

zolt
+ Math.floor(3.7) = {{ Math.floor(3.7) }}
+ Math.ceil(3.2) = {{ Math.ceil(3.2) }}
+ Math.round(3.5) = {{ Math.round(3.5) }}
+ Math.abs(-5) = {{ Math.abs(-5) }}
+ Math.min(10, 5) = {{ Math.min(10, 5) }}
+ Math.max(10, 5) = {{ Math.max(10, 5) }}
+ Math.pow(2, 8) = {{ Math.pow(2, 8) }}
+ Math.sqrt(16) = {{ Math.sqrt(16) }}
Result
  • Math.floor(3.7) = 3
  • Math.ceil(3.2) = 4
  • Math.round(3.5) = 4
  • Math.abs(-5) = 5
  • Math.min(10, 5) = 5
  • Math.max(10, 5) = 10
  • Math.pow(2, 8) = 256
  • Math.sqrt(16) = 4

List Namespace

The List namespace provides functions for manipulating arrays.

FunctionArgumentsReturnDescription
List.length(l)l: arraynumberReturns the number of elements in the list.
List.count(l)l: arraynumberAlias of List.length.
List.first(l)l: arrayanyReturns the first element of the list.
List.last(l)l: arrayanyReturns the last element of the list.
List.sum(l)l: arraynumberReturns the sum of all numeric elements in the list.
List.avg(l)l: arraynumberReturns the average value of numeric elements in the list.
List.min(l)l: arraynumberReturns the smallest numeric value in the list.
List.max(l)l: arraynumberReturns the largest numeric value in the list.

Examples

zolt
$numbers = [10, 20, 30, 40, 50]

+ Length: {{ List.length($numbers) }}
+ First: {{ List.first($numbers) }}
+ Last: {{ List.last($numbers) }}
+ Sum: {{ List.sum($numbers) }}
+ Average: {{ List.avg($numbers) }}
Result
  • Length: 5
  • First: 10
  • Last: 50
  • Sum: 150
  • Average: 30

String Namespace

The String namespace provides functions for string manipulation.

FunctionArgumentsReturnDescription
String.upper(s)s: stringstringReturns the string converted to uppercase.
String.lower(s)s: stringstringReturns the string converted to lowercase.
String.length(s)s: stringnumberReturns the number of characters in the string.
String.trim(s)s: stringstringReturns the string with whitespace removed from both ends.
String.replace(s, f, r)s: string, f: string, r: stringstringReplaces all occurrences of f with r in s.
String.split(s, sep)s: string, sep: stringarraySplits the string into an array of strings by separator.
String.join(l, sep)l: array, sep: stringstringJoins all elements of an array into a string using the separator.

Examples

zolt
{{ String.upper("hello") }}
{{ String.lower("HELLO") }}
{{ String.length("text") }}
{{ String.trim("  text  ") }}
{{ String.replace("hello", "l", "r") }}
Result
  • String.upper("hello") = HELLO
  • String.lower("HELLO") = hello
  • String.length("text") = 4
  • String.trim(" text ") = text
  • String.replace("hello", "l", "r") = herro

Date Namespace

The Date namespace provides functions for date and time operations.

FunctionArgumentsReturnDescription
Date.buildTime()NonenumberReturns the generation timestamp in milliseconds.
Date.format(d, f)d: timestamp/date/str, f: stringstringFormats a date according to the provided format string.
Date.parse(s, f?)s: string, f: string?dateParses a string into a Date object (optionally using a format).
Date.calc(d, dur)d: date, dur: objectdateAdds/subtracts time from a date (e.g., {days: 1}).
Date.diff(d1, d2, u?)d1: date, d2: date, u: string?numberReturns the difference between two dates in the specified unit.
Date.timestamp(d?)d: date?numberReturns the Unix timestamp (seconds) for a date or now.
Date.msTimestamp(d?)d: date?numberReturns the timestamp (milliseconds) for a date or now.

Format Tokens

Available format tokens:

TokenDescriptionExample
DDay (1-2 digits)3
DDDay (2 digits)03
dddDay name (short)tue
DddDay name (short, Capital)Tue
DDDDay name (short, Uppercase)TUE
ddddDay name (full)tuesday
DdddDay name (full, Capital)Tuesday
DDDDDay name (full, Uppercase)TUESDAY
MMonth (1-2 digits)3
MMMonth (2 digits)03
mmmMonth name (short)mar
MmmMonth name (short, Capital)Mar
MMMMonth name (short, Upper)MAR
mmmmMonth name (full)march
MmmmMonth name (full, Capital)March
MMMMMonth name (full, Upper)MARCH
YYYear (2 digits)26
YYYYYear (4 digits)2026
hHour (12h, 1-12)1
HHour (24h, 0-23)13
hhHour (12h, 01-12)01
HHHour (24h, 00-23)13
aam/pm (lowercase)pm
AAM/PM (uppercase)PM
mMinutes (0-59)12
mmMinutes (00-59)12
sSeconds (0-59)59
ssSeconds (00-59)59
sssMilliseconds (000-999)750

Examples

zolt
$created = "2024-01-01"

+ Date.buildTime() = {{ Date.buildTime() }}
+ Date.format($created, "DD/MM/YYYY") = {{ Date.format($created, "DD/MM/YYYY") }}
+ Date.timestamp($created) = {{ Date.timestamp($created) }}
+ Date.msTimestamp($created) = {{ Date.msTimestamp($created) }}
Result
  • Date.buildTime() = 1772543579751
  • Date.format($created, "DD/MM/YYYY") = 01/01/2024
  • Date.timestamp($created) = 1704067200
  • Date.msTimestamp($created) = 1704067200000

Best Practices

  1. Test complex calculations separately to ensure accuracy
  2. Use parentheses to make operator precedence explicit and readable
  3. Handle null/undefined variables before performing math
  4. Use namespace functions for formatting and common transformations

© 2026 Marmotz