Skip to main content

Numbers

Arithmetic helper functions returning numerical values as the result.

absolute​

Returns the absolute value of the context argument.

Usage:

{{absolute -123.45}} → 123.45

The argument is coerced into a number if possible. See number.

add​

Returns the sum the context argument and all params.

Usage:

{{add -123 0.45}} → -122.55
{{add -123 0.45 3.14}} → -119.41

The arguments are coerced into a number if possible. See number.

ceiling​

Returns the smallest integer that is not less than the argument.

Usage:

{{ceiling -123.45}} → -123
{{ceiling 123.55}} → -123

See the similar XPath 1.0 function.

divide​

Returns the division of the first (context) argument and all params.

Usage:

{{divide -123 2}} → -61.5
{{divide -123 2 3.14}} → -19.5859872611

The arguments are coerced into a number if possible. See number.

floor​

Returns the largest integer that is not greater than the argument.

Usage:

{{floor 123.45 }} → 123
{{floor -123.55 }} → -124

See the similar XPath 1.0 function.

modulo​

Returns the remainder of a division, after one number is divided by another.

This will internally return an integer or a float depending on the number type of the arguments.

Usage:

{{modulo 14 3 }} → 2
{{modulo 14.5 3.5 }} → 0.5

The arguments are coerced into a number if possible. See number.

multiply​

Returns the multiplication of the first (context) argument and all params.

Usage:

{{multiply -123 2.5}} → -307.5
{{multiply -123 2.5 3}} → -922.5
{{multiply -123 2.5 'foo' 3}} → -922.5

The arguments are coerced into a number if possible. See number. Arguments that cannot be coerced into a number will be ignored.

negate​

Returns the negation of the first (context) argument.

Usage:

{{negate '-42' }} → 42.0

The argument is coerced into a number if possible. See number. Arguments that cannot be coerced into a number will be ignored.

number​

Converts the argument to a number.

{{nnumber '123' }} → 123.0
  • null values produce 0
  • boolean true produces 1, boolean false produces 0
  • strings are parsed as Java double values.
  • unparseable values produce null.

See the similar XPath 1.0 function.

power​

Raises a number to the power of the second argument.

{{power 27 0.3 }} → 2.687875379522
{{power 144 0.5 }} → 12.0

round​

Returns an integer closest in value to the argument.

{{round 12.345}} → 12
{{round 12.345 precision=2}} → 12.35

See the similar XPath 1.0 function.

subtract​

Returns the subtraction of the context argument and all params.

Usage:

{{subtract 5 2}} → 3.0
{{subtract -123 0.45 3.14}} → -126.59

The arguments are coerced into a number if possible. See number. Arguments that cannot be coerced into a number will be ignored.