# xs:double

Converts $string-var (a string) to a double precision (64 bit) floating point value.

The data type double corresponds to IEEE double-precision 64-bit floating point type (IEEE 754-1985).

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

### Signatures

xs:double(xs:string $string-var) —> xs:double

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string | $string-var | Represents the string to convert to a double.

### Returns

Returns the double precision floating point value of $string-var.

### Examples

#### Simple

Invoking double("1.1")returns the double precision floating point value of 1.1 as shown in the following example query:

    <double>{xs:double("1.1")}</double>

The preceding query generates the following result:

    <double>1.1</double>

#### Exponent

Invoking double("-104.345e2")returns the double floating point value of -10434.5 as shown in the following example query:

    <double>{xs:double("-104.345e2")}</double>

The preceding query generates the following result:

    <double>-10434.5</double>

#### NaN

The string: NaN (Not a Number) is a legal argument, as shown in the following example query:

    <double>{xs:double("NaN")}</double>

The preceding query generates the following result:

    <double>NaN</double>

#### INF and -INF

The strings: INF (positive infinity) and -INF (negative infinity) are legal arguments as shown in the following example query:

    <infinity>
    	<positive>{xs:double("INF")}</positive>
    	<negative>{xs:double("-INF")}</negative>
    </infinity>

The preceding query generates the following result:

    <infinity>
    	<positive>Infinity</positive>
    	<negative>-Infinity</negative>
    </infinity>

#### Error—Invalid Exponent

Invoking double("10.1e2.1") outputs an error because 2.1 is not an integer. For example, the following example query:

    <double>{xs:double("10.1e2.1")}</double>

Produces the following error:

    Error occurred while executing XQuery: Could not cast "10.1e2.1" to type [double@http://www.w3.org/2001/XMLSchema]

#### Error—Null

Invoking double(()) returns the empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL

For example, the following example query:

    <double>{xs:double(())}</double>

The preceding query generates the following result:

    <double/>

Related Topics

W3C double data type description