ILE C/C++ Programmer's Guide
If the value of a _DecimalT class template that is to be
converted to another _DecimalT class template is not within the
range of values that can be represented exactly, the value of the
_DecimalT class template to be converted is truncated, as shown in
the following figure.
Figure 295. Example of Converting a Value from One _DecimalT Class Template to Another
_DecimalT<4,2> targ_1, targ_2;
_DecimalT<6,2> op_1=__D("1234.56"), op_2=__D("12.34");
targ_1=op_1; // A run-time exception is generated because the integral
// part is truncated; targ_1=__D("34.56").
targ_2=op_2; // No run-time exception is generated because neither the
// integral nor the fractional part is truncated;
// targ_2=__D("12.34").
|
Notes:
- A run-time exception occurs on assignment to a smaller target only when
the integral part is truncated. If assignment causes truncation in the
integral part, then there is a run-time exception in which a
_DecErrDigTruncated object is thrown. This run-time
exception occurs when an integral value is lost during conversion to a
different type, regardless of what operation requires the conversion.
For information on run-time exceptions during conversions, see _DecimalT Class Template Run-Time Exceptions.
- If truncation occurs in the fractional part, there is no run-time
exception.
When one_DecimalT class template is assigned to another
_DecimalT class template with a smaller precision, the result is
truncation of the fractional part, as shown in the following figure.
Figure 296. Example of Conversion from One _DecimalT Class Template to Another with Smaller Precision
_DecimalT<7,4> x = __D("123.4567");
_DecimalT<7,1> y;
y = x; // y = __D("123.4")
|
When one _DecimalT class template is assigned to another
_DecimalT class template with a smaller integral part, the result
is truncation of the integral part, as shown in the following figure.
Figure 297. Example of Conversion from One _DecimalT Class Template to Another with a Smaller Integral Part
_DecimalT<8,2> x = __D("123456.78");
_DecimalT<5,2> y;
y = x; // y = __D("456.78")
|
- Note:
- A run-time exception occurs on assignment to a smaller target only when the
integral part is truncated. For more information on run-time exceptions
during conversions, see _DecimalT Class Template Run-Time Exceptions.
When one _DecimalT class template is assigned to another
_DecimalT class with a smaller integral part, and smaller
precision, the result is truncation of the integral, and fractional parts, as
shown in the following figure.
Figure 298. Example of Conversion from One _DecimalT Class Template to Another with a Smaller Integral Part and Smaller Precision
_DecimalT<8,2> x = __D("123456.78");
_DecimalT<4,1> y;
y = x; // y = __D("456.7")
|
- Note:
- A run-time exception occurs on assignment to a smaller target only when the
integral part is truncated. For more information on run-time exceptions
during conversions, see _DecimalT Class Template Run-Time Exceptions.
[ Top of Page | Previous Page | Next Page | Table of Contents ]
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.