ILE C/C++ Programmer's Guide

Converting Values from a _DecimalT Class Template to an Integer Data Type

When a value of a _DecimalT class template is converted to an integer type:

Note:
No run-time exception occurs when assigning a _DecimalT class template to an integer type that results in truncation of the integral part.

Figure 299. Example of Converting an Integer Type to a _DecimalT Class Template with a Fractional Part



int op;
_DecimalT<7,2> op1 = __D("12345.67");
op = op1; // Truncation on the fractional
// part. op=12345

Figure 300. Example of Converting an Integer Type to a _DecimalT Class Template with Less than 10 Digits in the Integral Part



int op;
_DecimalT<3, 0> op2 = __D("123");
op = op2; // No truncation; op=123

Figure 301. Example of Converting to an Integer Type from a _DecimalT Class Template with More than 10 Digits in the Integral Part



int op2;
_DecimalT<12, 0> op3;
op3 = __D("123456789012");
op2 = op3; // Truncation occurs on the integral
// part. op2=3456789012; no runtime
// exception.

Figure 302. Example of Converting to an Integer Type from a _DecimalT Class Template with a Fractional Part, and with an Integral Part that Has More than 10 Digits



#include <bcd.h>

int op;
_DecimalT<15,2> op_1 = __D("1234567890123.12");
op = op_1; // Truncation occurs on the integral and
// fractional parts. op=4567890123; no
// run-time exception.


[ Top of Page | Previous Page | Next Page | Table of Contents ]