Skip to content
Numeric Functions

Numeric Functions

abs

abs($arg as numeric) as numeric

Returns the absolute value of $arg.

abs(-5)  →  5

avg

avg($arg as xs:anyAtomicType*) as xs:anyAtomicType?

Returns the average of the values in $arg.

avg((1, 2, 3, 4))  →  2.5

ceiling

ceiling($arg as numeric) as numeric

Returns the smallest integer greater than or equal to $arg.

ceiling(3.2)  →  4

floor

floor($arg as numeric) as numeric

Returns the largest integer less than or equal to $arg.

floor(3.8)  →  3

max

max($arg as xs:anyAtomicType*) as xs:anyAtomicType?

Returns the maximum value from a sequence.

max((1, 5, 3))  →  5

min

min($arg as xs:anyAtomicType*) as xs:anyAtomicType?

Returns the minimum value from a sequence.

min((1, 5, 3))  →  1

number

number($arg as xs:anyAtomicType?) as xs:double

Converts the argument to a double.

round

round($arg as numeric?) as numeric?

Rounds to the nearest integer (0.5 rounds up).

round(2.5)  →  3

round-half-to-even

round-half-to-even($arg as numeric?) as numeric?

round-half-to-even($arg as numeric?, $precision as xs:integer) as numeric?

Rounds to the given precision using banker’s rounding (half-to-even).

round-half-to-even(2.5)  →  2
round-half-to-even(3.5)  →  4

sum

sum($arg as xs:anyAtomicType*) as xs:anyAtomicType

Returns the sum of the values in $arg.

sum((1, 2, 3))  →  6

format-number

format-number($value as numeric, $picture as xs:string) as xs:string

format-number($value as numeric, $picture as xs:string, $name as xs:string) as xs:string

Formats a number as a string according to the picture string.

format-number(1234.5, '#,##0.00')  →  "1,234.50"

format-integer

format-integer($value as xs:integer, $picture as xs:string) as xs:string

Formats an integer according to the picture string.

format-integer(42, 'w')  →  "forty-two"