.. _number:
======
number
======
Converts a value or a node to a number
Description
~~~~~~~~~~~
The fn:number function constructs an xs:double value either from a node that
contains a number, or from an atomic value. This function is useful for telling
the processor to treat a node or value as a number, regardless of its declared
type (if any). It returns the argument cast as an xs:double.
The difference between using the fn:number function and the xs:double
constructor is that the fn:number function returns the value NaN in the case
that the argument cannot be cast to a numeric value, whereas the xs:double
constructor will raise an error.
.. list-table::
:widths: 40 60
:header-rows: 1
* - **Parameters**
- **Description**
* - arg:integer()
-
Examples
~~~~~~~~
.. list-table::
:widths: 50 50
:header-rows: 1
* - **XPath**
- **Results**
* - number($priceDoc//prod[1]/price)
- 29.99
* - number($priceDoc//prod/price)
- Error XPTY0004
* - number($priceDoc//prod[1]/@currency)
- NaN
* - number('29,99')
- 29.99
* - number('ABC')
- NaN
* - number( () )
- NaN
* - $priceDoc//prod/price[number() > 35]
- 69.99 39.99
See Also
~~~~~~~~
.. toctree::
:titlesonly:
:glob:
* :ref:`functx_is-a-number`.