home contribute faq download

FunctX XQuery Functions

fn:number

Converts a value or a node to a number

Google
Webxqueryfunctions.com

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.

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

NameType
$arg xs:anyAtomicType?
return value xs:double

Examples

let $priceDoc :=
doc('http://www.functx.com/input/prices.xml')
return
XQuery ExampleResults
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

functx:is-a-numberWhether a value is numeric

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XQuery Services

Recommended Reading:

XQuery