To use the IBinaryCodedDecimal class, you must either:
#include <idecimal.hpp>
You can use the IBinaryCodedDecimal constructor to construct IBinaryCodedDecimal objects or arrays of IBinaryCodedDecimal objects. The following example shows how to construct an IBinaryCodedDecimal object to have a value (12) with DFT_LNG_DIG, number of digits (20) and number of precisions (0):
IBinaryCodedDecimal a(12L);
The following example shows how to construct an IBinaryCodedDecimal object to have a value INT_MAX with number of digits (16) and number of precisions (5):
IBinaryCodedDecimal b(16,5,INT_MAX);
If accuracy of IBinaryCodedDecimal is important, use the char * constructor instead of the floating type constructor. For example, use:
IBinaryCodedDecimal accurateBCD("12345.6789");
// this will store exactly 12345.6789
instead of :
IBinaryCodedDecimal roughBCD(12345.6789); // this will store something close to 12345.6789 // (might be 12345.6788999999999..., depends on the // floating type representation)
Constants Defined in idecimal.hpp
The table below lists the binary coded decimal constants that the Binary Coded Decimal Class Library defines:
| Constant Name | Description |
|---|---|
| DEC_DIG | The maximum number of significant digits that IBinaryCodedDecimal can hold. |
| DEC_MIN | The minimum value that IBinaryCodedDecimal can hold. |
| DEC_MAX | The maximum value that IBinaryCodedDecimal can hold. |
| DEC_EPSILON | The smallest incremental or decremental value that IBinaryCodedDecimal can hold. |
| DFT_DIG | The default number of digits (15) for the default constructor. |
| DFT_PREC | The default number of precision (5) for the default constructor. |
| DFT_LNG_DIG | The default number of digits (20) for a long type. |
When you use the member function precisionOf() with an IBinaryCodedDecimal object, you can find out the number of decimal digits p in an IBinaryCodedDecimal object:
int p; IBinaryCodedDecimal x(5, 2); p=x.precisionOf(); // The result is p=2
When you use the member function digitsOf() with an IBinaryCodedDecimal object, you can find out the total number of digits n in an IBinaryCodedDecimal object:
int n; IBinaryCodedDecimal x(5, 2); n = x.digitsOf(); // the result is n=5
![]()
Performing Calculations
Using IBinaryCodedDecimal
Assigning One
IBinaryCodedDecimal to Another
Assigning an
IBinaryCodedDecimal to an Integer
Assigning an
IBinaryCodedDecimal to a Float
![]()
What Is a
Binary Coded Decimal