Name

number( ) — converts another datatype into a number

Synopsis

Defined in: XPath 1.0
Parameters: object num (required)
Return type: number

Other datatypes are converted according to the following rules:

string

A string that represents a number (ignoring leading and trailing whitespace) is converted into a number. Any string that can’t be converted this way results in a return value of NaN.

boolean

true produces 1 and false produces 0.

node-set

A node-set is first converted into a string (as with string( )), then converted into a number by the rules for a string.

When called with no parameters, the converted value of the context node is returned.

The following example returns NaN:

number("three")

Get XForms Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.