Objects of the IBinaryCodedDecimal class represent numerical quantities accurately, especially in business and commercial applications for financial calculations.
This class provides functions to obtain information about, compare, and manipulate IBinaryCoded Decimal objects.
Construct and destruct BCD objects.
![]() |
The IBinaryCodedDecimal object can be constructed in many different ways. If the number of digits and precisions are provided, the constructed object has the provided digit and precision; otherwise default values are assumed according to the type of the value. If a value is provided during construction, the constructed object has the given value with the appropiate digit and precision; otherwise the constructed object will have a value zero. An exception is thrown if the number of digits in the integral part is larger than the supported value (for example, DEC_DIG) or the provided digit and/or precision are out of range. The valid values should satisfy the following:
DIGITS - the given number of digits PRECISIONS - the given number of precisions0 < DIGITS <= DEC_DIG 0 <= PRECISIONS <= DEC_DIG PRECISIONS <= DIGITS
All the macro constants are defined in :xph.idecimal.hpp:exph..
public:
IBinaryCodedDecimal(long double alDouble)
Constructs the IBinaryCodedDecimal object to have a value
alDouble.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, long double alDouble )
Constructs the IBinaryCodedDecimal object to have a value
alDouble with nDig number of digits and
nPrec number of precisions.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(double aDouble)
Constructs the IBinaryCodedDecimal object to have a value
aDouble.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(unsigned long auLong)
Constructs the IBinaryCodedDecimal object to have a value auLong with DFT_LNG_DIG number of digits and zero number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(unsigned int nDig, unsigned int nPrec)
Constructs the IBinaryCodedDecimal object to have a value zero with nDig number of digits and nPrec number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(int anInt)
Constructs the IBinaryCodedDecimal object to have a value anInt with DFT_INT_DIG number of digits and zero number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(unsigned int auInt)
Constructs the IBinaryCodedDecimal object to have a value auInt with DFT_INT_DIG number of digits and zero number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal()
This is a default constructor. The constructed object has a value zero with attributes of DFT_DIG number of digits and DFT_PREC number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(const char* val)
Constructs the IBinaryCodedDecimal object according to the value represented in the provided string. The number of digits and precisions are set accordingly. The leading and trailing zeros are used when setting up the digit and precision attributes, for example, "00123.4560" has 9 digits and 4 precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, long aLong )
Constructs the IBinaryCodedDecimal object to have a value aLong with nDig number of digits and nPrec number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(long aLong)
Constructs the IBinaryCodedDecimal object to have a value aLong with DFT_LNG_DIG number of digits and zero number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, unsigned long auLong )
Constructs the IBinaryCodedDecimal object to have a value auLong with nDig number of digits and nPrec number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, int anInt )
Constructs the IBinaryCodedDecimal object to have a value anInt with nDig number of digits and nPrec number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, unsigned int auInt )
Constructs the IBinaryCodedDecimal object to have a value auInt with nDig number of digits and nPrec number of precisions.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, float afloat )
Constructs the IBinaryCodedDecimal object to have a value
afloat with nDig number of digits and
nPrec number of precisions.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal(float afloat)
Constructs the IBinaryCodedDecimal object to have a value
afloat.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal( unsigned int nDig, unsigned int nPrec, double aDouble )
Constructs the IBinaryCodedDecimal object to have a value
aDouble with nDig number of digits and
nPrec number of precisions.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
These operators allow you to assign various forms of numbers to a IBinaryCodedDecimal object.
![]() |
public:
IBinaryCodedDecimal& operator =(unsigned auInt)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(int anInt)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(long double alDouble)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =( const IBinaryCodedDecimal& bcd )
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(long aLong)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(const IDecimalUtil& dut)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(unsigned long auLong)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(double aDouble)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal& operator =(float aFloat)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
Use these operators to compare BCD objects for equality and/or relative magnitude.
![]() |
public:
int operator !=(const IDecimalUtil& dut) const
This operator is used to compare two IBinaryCodedDecimal
objects. The right IBinaryCodedDecimal object is converted
to the utility class, IDecimalUtil first. Returns 1 if the
represented values in both object are not the same;
otherwise returns 0.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int operator <(const IDecimalUtil& dut) const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int operator <=(const IDecimalUtil& dut) const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int operator ==(const IDecimalUtil& dut) const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int operator >(const IDecimalUtil& dut) const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int operator >=(const IDecimalUtil& dut) const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
Use these operators and methods to perform common operations on BCD objects.
![]() |
public:
int operator !() const
Returns 1 if the IBinaryCodedDecimal object contains the value zero; otherwise returns 0.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
void operator *=(const IDecimalUtil& dut)
This operator is used to perform compound assignment
between two IBinaryCodedDecimal objects.
The right IBinaryCodedDecimal object is converted
to the utility class, IDecimalUtil first. The left operand
is multiplied by the right operand, the result is stored
back to the left operand.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
IBinaryCodedDecimal operator +() const
This is a unary plus operator. The copy of the original object is returned.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
This is a increment operator.
public:
IBinaryCodedDecimal operator ++()
This is a prefix increment operator. The value being represented is incremented by 1 and the object with the new value is returned.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal operator ++(int)
This is a postfix increment operator. The original object is returned. As a side effect, the value being represented is incremented by 1.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
void operator +=(const IDecimalUtil& dut)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
IBinaryCodedDecimal operator -() const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
IBinaryCodedDecimal operator --(int)
This is a postfix decrement operator. The original object is returned. As a side effect, the value being represented is decremented by 1.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
public:
IBinaryCodedDecimal operator --()
This is a prefix decrement operator. The value being represented is decremented by 1 and the object with the new value is returned.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
void operator -=(const IDecimalUtil& dut)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
void operator /=(const IDecimalUtil& dut)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
The methods query the object for status information.
![]() |
public:
const char* cData() const
Returns a pointer that points to the internal buffer which contains the binary coded decimal value in packed decimal format, for example two digits per byte, the last right nibble contains the sign.
This expression
:xph.(digitsOf() >> 1) + 1:exph. identifies the number of bytes to
store the binary coded decimal value.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int digitsOf() const
Returns the number of digits represented by the binary coded decimal value.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
const bool isNegative() const
Returns true if the IBinaryCodeDecimal object represents a negative value; otherwise returns false.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
const bool isPositive() const
Returns true if the IBinaryCodeDecimal object represents
a positive value; otherwise returns false.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
int precisionOf() const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
These operators and methods support binary streaming of BCD objects.
![]() |
public:
void operator <<=(IDataStream& fromWhere)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
void operator >>=(IDataStream& toWhere)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
protected:
void readFromStream(IDataStream& fromWhere)
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
protected:
void writeToStream(IDataStream& toWhere) const
Windows | OS/2 | AIX |
Yes | Yes | Yes |
These methods return the BCD value as binary or text.
![]() |
public:
double asDouble() const
Returns the binary coded decimal as a double value.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
long asLong() const
Returns the binary coded decimal as a long type value. Any numbers after the decimal point are truncated. If the value in the binary coded decimal is too large or too small to be represented as a long type, the returned value is undefined.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
IString asString() const
Returns the binary coded decimal as IString representation.
Windows | OS/2 | AIX |
Yes | Yes | Yes |