round function
The fn:round function returns the integer that is closest to a specific numeric value.
Syntax
- numeric-value
- An atomic value or an empty sequence.If numeric-value is an atomic value, it has one of the following types:
- xs:float
- xs:double
- xs:decimal
- xs:integer
- xdt:untypedAtomic
- A type that is derived from any of the previously listed types
If numeric-value has the xdt:untypedAtomic data type, it is converted to an xs:double value.
Returned value
If numeric-value is
not the empty sequence, the returned value is the integer that is
closest to numeric-value. That is, fn:round(numeric-value)
is equivalent to fn:floor(numeric-value+0.5). The data type
of the returned value depends on the data type of numeric-value:
- If numeric-value is xs:float, xs:double, xs:decimal, or xs:integer, the value that is returned has the same type as numeric-value.
- If numeric-value has a data type that is derived from xs:float, xs:double, xs:decimal, or xs:integer, the value that is returned has the direct parent data type of numeric-value.
If numeric-value is the empty sequence, the returned value is the empty sequence.
Examples
Example with a positive argument: The
following function returns the rounded value of 0.5:
fn:round(0.5)
The returned value is 1.
Example with a negative argument: The
following function returns the rounded value of (-1.5):
fn:round(-1.5)
The returned value is -1.