# xs:integer

Converts $string-var (a string) to an integer value.

If the value of $string-var is greater than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808, the TransformException exception is raised with the SYS_LONG_OVERFLOW fault code. The following error message is displayed in the mapper:

    Error occurred while executing XQuery: BigDecimal -> Long overflow!

Note: For performance reasons, the integer supported by this XQuery engine is equivalent to a Java long, which is smaller then the W3C XML Schema integer, which has an arbitrary length. To learn more, see the integer description.

Note: The value $string-var must be specified without commas as shown in the following example invocation:

xs:integer("999999999")

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.

To learn more about using fault codes, see Getting the TransformException Fault Code Programmatically.

### Signatures

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

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string | $string-var | Represents the string to convert to an integer value.

### Returns

Returns an integer value of $string-var.

### Examples

#### Simple

Invoking integer("10402") returns the integer value 10402 as shown in the following example query:

    <integer>{xs:integer("10402")}</integer>

The preceding query generates the following result:

    <integer>10402</integer>

#### Error—Decimal Point is Not Allowed

Invoking integer("104.0") outputs an error because the decimal point is not allowed in the argument.

For example, the following example query:

    <integer>{xs:integer("104.0")}</integer>

Produces the following error:

    Error occurred while executing XQuery: Could not cast "104.0" to type [integer@http://www.w3.org/2001/XMLSchema]

#### Error—Not a Number

Invoking integer("foo") outputs an error because "foo" is not a number.

For example, the following example query:

    <integer>{xs:decimal("foo")}</integer>

Produces the following error:

    Error occurred while executing XQuery: Could not cast "foo" to type [integer@http://www.w3.org/2001/XMLSchema]

#### Null

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

For example, the following example query:

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

The preceding query generates the following result:

    <integer/>

### XQuery Compliance

An integer value in this XQuery engine has a maximum size of 9,223,372,036,854,775,807 and a minimum size of -9,223,372,036,854,775,808. For performance reasons, the integer supported by this XQuery engine is equivalent to a Java long, which is smaller then the W3C XML Schema integer, which has an arbitrary length.

Related Topics

integer data type description

Getting the TransformException Fault Code Programmatically