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.

Parameters

Description

arg:integer()

Examples

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]

<price currency=”USD”>69.99</price> <price currency=”USD”>39.99</price>

See Also