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 |
|
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 ...