# Chapter 17. Working with Numbers

A variety of numerical calculations can be performed using XQuery. This chapter describes the major numeric types, along with the operators and functions that act on numeric values. These include comparisons, arithmetic operations, and functions that operate on numeric values such as `round` and `sum`.

# The Numeric Types

The four main numeric types supported in XQuery are `xs:decimal`, `xs:integer`, `xs:float`, and `xs:double`. All the operations and functions that can be performed on these types of numeric values can also be performed on values whose types are restrictions of these types. This includes user-defined types that appear in a schema, as well as the built-in derived types such as `xs:positiveInteger` and `xs:unsignedByte`. For a complete list and explanation of these built-in derived types, see Appendix B.

## The `xs:decimal` Type

The type `xs:decimal` represents a signed decimal number of implementation-defined precision. Numeric literals that contain only digits and a decimal point (no letter `E` or `e`) are considered decimal numbers, with the type `xs:decimal`. For example, `25.5` and `25.0` are `xs:decimal` values.

## The `xs:integer` Type

The type `xs:integer` represents a signed integer. The limit on how large an `xs:integer` value can be is implementation-defined. Numeric literals that contain only digits (no decimal points or the letter `E` or `e`) are considered integers, with the type `xs:integer`. For example, `25` is an `xs:integer` value.

In the type hierarchy, `xs:integer` is derived ...

Get XQuery, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.