Skip to content

Number Functions

Number functions format and manipulate numeric values. Non-numeric inputs are cast to float (0.0 for non-numeric strings).

number_format

Formats a number with a specified number of decimal places and thousands separators.

Signature: number_format(value, decimals?)

ParameterTypeDefaultDescription
valuenumber--The number to format.
decimalsnumber0Number of decimal places.
`{ {number_format(row.price, 2)}}`
// 1234.5 → "1,234.50"

`{ {number_format(row.count)}}`
// 15000 → "15,000"

$`{ {number_format(row.total, 2)}}`
// 99.9 → "$99.90"

round

Rounds a number to the specified precision.

Signature: round(value, precision?)

ParameterTypeDefaultDescription
valuenumber--The number to round.
precisionnumber0Number of decimal places.
`{ {round(row.average, 1)}}`
// 4.567 → 4.6

`{ {round(row.score)}}`
// 87.4 → 87

floor

Rounds a number down to the nearest integer.

Signature: floor(value)

`{ {floor(row.rating)}}`
// 4.9 → 4

`{ {floor(row.price / 10) * 10}}`
// 47.50 → 40 (round down to nearest ten)

ceil

Rounds a number up to the nearest integer.

Signature: ceil(value)

`{ {ceil(row.pages / 10)}}`
// 25 / 10 = 2.5 → 3 (total page groups)

`{ {ceil(row.weight)}}`
// 2.1 → 3

abs

Returns the absolute (non-negative) value.

Signature: abs(value)

`{ {abs(row.change)}}`
// -15.5 → 15.5

`{ {abs(row.balance)}}`
// -200 → 200

min

Returns the smaller of two values.

Signature: min(a, b)

`{ {min(row.price, 99.99)}}`
// Cap at 99.99

`{ {min(row.quantity, row.stock)}}`
// Don't exceed available stock

max

Returns the larger of two values.

Signature: max(a, b)

`{ {max(row.score, 0)}}`
// Ensure non-negative

`{ {max(row.price - row.discount, 0)}}`
// Price after discount, minimum 0

Combining Number Functions

$`{ {number_format(max(row.price * row.quantity - row.discount, 0), 2)}}`
// Format: "$1,234.50" with discount applied, minimum $0

`{ {round(row.sum / max(row.count, 1), 2)}}`
// Safe average (avoid division by zero)

`{ {ceil(row.total_items / 10)}}` pages
// "3 pages" for 25 items