Loading TOC...

MarkLogic 9 Product Documentation
fn.number

fn.number(
   [arg as xs.anyAtomicType?]
) as Number

Summary

Returns the value indicated by $arg or, if $arg is not specified, the context item after atomization, converted to an xs:double. 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].

Calling the zero-argument version of the function is defined to give the same result as calling the single-argument version with an argument of ".". That is, fn:number() is equivalent to fn:number(.).

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.

Parameters
arg The value to be returned as an xs:double value.

Example

var item1 = fn.head(xdmp.unquote('<a><quantity>5.0</quantity></a>')).root
fn.number(item1.xpath("/a/quantity"));
=> 5

var item1 = fn.head(xdmp.unquote('<a><quantity>5.0</quantity></a>')).root
fn.number(item1.xpath("/quantity"));
=> NaN

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.