fn:number()
Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double
Calling the zero-argument version of the function is defined to give the same result as calling the single-argument version with the context item (.). That is, fn:number() is equivalent to fn:number(.).
If $arg is the empty sequence or if $arg or the context item cannot be converted to an xs:double, the xs:double value NaN is returned. If the context item is undefined an error is raised: [err:XPDY0002]XP.
If $arg is the empty sequence, NaN is returned. Otherwise, $arg, or the context item after atomization, is converted to an xs:double following the rules of 17.1.3.2 Casting to xs:double. If the conversion to xs:double fails, the xs:double value NaN is returned.
Arguments:
| Type |
Description |
| xs:anyAtomicType? |
Value to convert to number |
Return type: xs:double
W3C Documentation reference
fn:abs()
Returns the absolute value of $arg. If $arg is negative returns -$arg otherwise returns $arg. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive zero or negative zero, then positive zero is returned. If the argument is positive or negative infinity, positive infinity is returned.
For detailed type semantics, see Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and fn:round-half-to-even functions.
Arguments:
| Type |
Description |
| numeric? |
$arg |
Return type: numeric?
Examples:
| Query |
Result |
| abs(-2) |
2 |
| abs(2137) |
2137 |
W3C Documentation reference
fn:ceiling()
Returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of $arg. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned. If the argument is less than zero and greater than -1, negative zero is returned.
Arguments:
| Type |
Description |
| numeric? |
$arg |
Return type: numeric?
Examples:
| Query |
Result |
| ceiling(10.5) |
11 |
| ceiling(-10.5) |
-10 |
| ceiling(10.1) |
11 |
W3C Documentation reference
fn:floor()
Returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of $arg. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For float and double arguments, if the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned.
Arguments:
| Type |
Description |
| numeric? |
$arg |
Return type: numeric?
Examples:
| Query |
Result |
| floor(10.5) |
10 |
| floor(-10.5) |
-11 |
| floor(10.8) |
10 |
W3C Documentation reference
fn:round()
Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
For xs:float and xs:double arguments, if the argument is positive infinity, then positive infinity is returned. If the argument is negative infinity, then negative infinity is returned. If the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned. If the argument is less than zero, but greater than or equal to -0.5, then negative zero is returned. In the cases where positive zero or negative zero is returned, negative zero or positive zero may be returned as [XML Schema Part 2: Datatypes Second Edition] does not distinguish between the values positive zero and negative zero.
For the last two cases, note that the result is not the same as fn:floor(x+0.5).
Arguments:
| Type |
Description |
| numeric? |
$arg |
Return type: numeric?
Examples:
| Query |
Result |
| round(10.5) |
11 |
| round(10.4999) |
10 |
| round(-10.5) |
-10 |
W3C Documentation reference
fn:round-half-to-even()
The value returned is the nearest (that is, numerically closest) value to $arg that is a multiple of ten to the power of minus $precision. If two such values are equally near (e.g. if the fractional part in $arg is exactly .500...), the function returns the one whose least significant digit is even.
If the type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.
The first signature of this function produces the same result as the second signature with $precision=0.
For arguments of type xs:float and xs:double, if the argument is NaN, positive or negative zero, or positive or negative infinity, then the result is the same as the argument. In all other cases, the argument is cast to xs:decimal, the function is applied to this xs:decimal value, and the resulting xs:decimal is cast back to xs:float or xs:double as appropriate to form the function result. If the resulting xs:decimal value is zero, then positive or negative zero is returned according to the sign of the original argument.
Note that the process of casting to xs:decimal may result in an error [err:FOCA0001].
If $arg is of type xs:float or xs:double, rounding occurs on the value of the mantissa computed with exponent = 0.
Arguments:
| Type |
Description |
| numeric? |
$arg |
| numeric? |
$precision (Optional) |
Return type: numeric?
Examples:
| Query |
Result |
| round-half-to-even(0.5) |
0 |
| round-half-to-even(1.5) |
2 |
| round-half-to-even(2.5) |
2 |
| round-half-to-even(2.6) |
3 |
W3C Documentation reference