Skip to Content
XQuery
book

XQuery

by Priscilla Walmsley
March 2007
Intermediate to advanced content levelIntermediate to advanced
512 pages
21h 15m
English
O'Reilly Media, Inc.
Content preview from XQuery

xs:decimal

The primitive type xs:decimal represents a decimal number. The lexical representation of xs:decimal is a sequence of digits that can be preceded by a sign (+ or -) and may contain a decimal point (.). Trailing zeros after the decimal point are not considered significant. That is, the decimal values 5.1 and 5.1000 are considered equal.

Table B-7 lists some values of the xs:decimal type.

Table B-7. Values of the xs:decimal type

Values

Explanation

Valid

 
5.0
 
−5.2

A sign is permitted

6

A decimal point is not required

0
 
0006.000

Leading and trailing zeros are valid

Invalid

 
5,6

The decimal separator must be a period, not a comma

1e6

Exponential notation is not allowed; use xs:float or xs:double instead

 

An empty value or zero-length string is not permitted

Implementations vary in the number of significant digits they allow. They are free to round or truncate values to the number of digits they support. If overflow occurs during arithmetic operations on xs:decimal values, an error is raised. When underflow occurs, the value 0.0 is returned.

Casting xs:decimal Values

Values of type xs:decimal can be cast to and from any of the other numeric types. Casting among numeric types is straightforward if the value is in the value space of both types. For example, casting an xs:decimal value 12.5 to xs:float results in a value 12.5E0 whose type is xs:float.

However, some xs:float or xs:double values cannot be cast to xs:decimal. An error is raised if you attempt ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XQuery, 2nd Edition

XQuery, 2nd Edition

Priscilla Walmsley
XPath and XPointer

XPath and XPointer

John Simpson
XQuery Kick Start

XQuery Kick Start

James McGovern, Per Bothner, Kurt Cagle, James Linn, Vaidyanathan Nagarajan
Learning XSLT

Learning XSLT

Michael Fitzgerald

Publisher Resources

ISBN: 0596006349Supplemental ContentErrata