Share via


CComCurrency Class

CComCurrency has methods and operators for creating and managing a CURRENCY object.

class CComCurrency

Remarks

CComCurrency is a wrapper for the CURRENCY data type. CURRENCY is implemented as an 8-byte two's-complement integer value scaled by 10,000. This gives a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right. The CURRENCY data type is extremely useful for calculations involving money, or for any fixed-point calculations where accuracy is important.

The CComCurrency wrapper implements arithmetic, assignment, and comparison operations for this fixed-point type. The supported applications have been selected to control the rounding errors that can occur during fixed-point calculations.

The CComCurrency object provides access to the numbers on either side of the decimal point in the form of two components: an integer component which stores the value to the left of the decimal point, and a fractional component which stores the value to the right of the decimal point. The fractional component is stored internally as an integer value between -9999 (CY_MIN_FRACTION) and +9999 (CY_MAX_FRACTION). The method CComCurrency::GetFraction returns a value scaled by a factor of 10000 (CY_SCALE).

When specifying the integer and fractional components of a CComCurrency object, remember that the fractional component is a number in the range 0 to 9999. This is important when dealing with a currency such as the US dollar that expresses amounts using only two significant digits after the decimal point. Even though the last two digits are not displayed, they must be taken into account.

Value

Possible CComCurrency assignments

$10.50

CComCurrency(10,5000) or CComCurrency(10.50)

$10.05

CComCurrency(10,500) or CComCurrency(10.05)

The values CY_MIN_FRACTION, CY_MAX_FRACTION, and CY_SCALE are defined in atlcur.h.

Requirements

Header: atlcur.h

See Also

Reference

COleCurrency Class

CURRENCY

Other Resources

CComCurrency Members

ATL Class Overview