Assigning One IBinaryCodedDecimal to Another

If the value of an IBinaryCodedDecimal object that is to be converted to another IBinaryCodedDecimal object is not within the range of values that can be represented exactly, the value of the IBinaryCodedDecimal object to be converted is truncated. If truncation occurs in the fractional part, there is no exception raised. If assignment causes truncation in the integral part, then there is an exception in which a IDecimalDataError object is thrown. This exception occurs when an integral value is lost during conversion to a different type, regardless of what operation requires the conversion:

IBinaryCodedDecimal targ_1(4,2);
IBinaryCodedDecimal targ_2(4,2);
IBinaryCodedDecimal op_1("1234.56");
IBinaryCodedDecimal op_2("12.34");
targ_1=op_1;   // An exception is generated because the integral
               // part is truncated; targ_1=("34.56").
targ_2=op_2;   // No exception is generated because neither the
               // integral nor the fractional part is truncated;
               // targ_2=("12.34").

An exception occurs on assignment to a smaller target only when the integral part is truncated.

When one IBinaryCodedDecimal object is assigned to another IBinaryCodedDecimal object with a smaller precision, the result is truncation of the fractional part:

IBinaryCodedDecimal x("123.4567");
IBinaryCodedDecimal y(7,1);
y = x;    // y = ("123.4")

When one IBinaryCodedDecimal object is assigned to another IBinaryCodedDecimal object with a smaller integral part, the result is truncation of the integral part. An exception occurs:

IBinaryCodedDecimal x("123456.78");
IBinaryCodedDecimal y(5,2);
y = x;   // y = ("456.78")

When one IBinaryCodedDecimal object is assigned to another IBinaryCodedDecimal object with a smaller integral part, and smaller precision, the result is truncation of the integral, and fractional parts. An exception occurs:

IBinaryCodedDecimal x("123456.78");
IBinaryCodedDecimal y(4,1);
y = x;  // y = ("456.7")


Representing Numerical Quantities Using IBinaryCodedDecimal
Performing Calculations Using IBinaryCodedDecimal
Assigning an IBinaryCodedDecimal to an Integer
Assigning an IBinaryCodedDecimal to a Float


What Is a Binary Coded Decimal