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 to cast to xs:decimal one of the special values NaN, INF or -INF, or a value that is too large or too small to be supported by the implementation.

You can cast xs:decimal values to xs:integer, in which case the value is truncated.

Values of type xs:decimal can also be cast to and from xs:string, xs:untypedAtomic, and xs:boolean. When cast to xs:string, the value will have no positive sign, no leading zeros, and no trailing zeros after the decimal point, except that there will always be at least one digit before the decimal point. If there is no fractional part, the decimal point is omitted. When cast to xs:boolean, the value 0 becomes false, and all other values become true.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.194.106