ILE C/C++ Programmer's Guide

Converting Values from a _DecimalT Class Template to a Floating Point Data Type

to convert a _DecimalT class template class to a floating point data type, use source code similar to that found in the following figure.

Figure 303. Example of Converting a _DecimalT Class Template to a Floating Point Data Type



#include <bcd.h>
#include <iostream.h>

int main(void)
{
_DecimalT<5,2> dec_1=__D("123.45");
_DecimalT<11,5> dec_2=__D("-123456.12345");

float f1,f2;

f1=dec_1;
f2=dec_2;

cout <<"f1=" <<f1 <<endl <<"f2=" <<f2 <<endl <<endl;//f1=123.45
// f2=-123456
}

The output is shown below.

+--------------------------------------------------------------------------------+
|  f1=123.45                                                                     |
|  f2=-123456                                                                    |
+--------------------------------------------------------------------------------+


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