description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CComCurrency Class |
CComCurrency Class |
11/04/2016 |
|
|
a1c3d10a-bba6-40cc-8bcf-aed9023c8a9e |
CComCurrency
has methods and operators for creating and managing a CURRENCY
object.
class CComCurrency;
Name | Description |
---|---|
CComCurrency::CComCurrency |
The constructor for a CComCurrency object. |
Name | Description |
---|---|
CComCurrency::GetCurrencyPtr |
Returns the address of an m_currency data member. |
CComCurrency::GetFraction |
Call this method to return the fractional component of a CComCurrency object. |
CComCurrency::GetInteger |
Call this method to return the integer component of a CComCurrency object. |
CComCurrency::Round |
Call this method to round a CComCurrency object to the nearest integer value. |
CComCurrency::SetFraction |
Call this method to set the fractional component of a CComCurrency object. |
CComCurrency::SetInteger |
Call this method to set the integer component of a CComCurrency object. |
Name | Description |
---|---|
CComCurrency::operator - |
This operator is used to perform subtraction on a CComCurrency object. |
CComCurrency::operator != |
Compares two CComCurrency objects for inequality. |
CComCurrency::operator * |
This operator is used to perform multiplication on a CComCurrency object. |
CComCurrency::operator *= |
This operator is used to perform multiplication on a CComCurrency object and assign it the result. |
CComCurrency::operator / |
This operator is used to perform division on a CComCurrency object. |
CComCurrency::operator /= |
This operator is used to perform division on a CComCurrency object and assign it the result. |
CComCurrency::operator + |
This operator is used to perform addition on a CComCurrency object. |
CComCurrency::operator += |
This operator is used to perform addition on a CComCurrency object and assign the result to the current object. |
CComCurrency::operator < |
This operator compares two CComCurrency objects to determine the lesser. |
CComCurrency::operator <= |
This operator compares two CComCurrency objects to determine equality or the lesser. |
CComCurrency::operator = |
This operator assigns the CComCurrency object to a new value. |
CComCurrency::operator -= |
This operator is used to perform subtraction on a CComCurrency object and assign it the result. |
CComCurrency::operator == |
This operator compares two CComCurrency objects for equality. |
CComCurrency::operator > |
This operator compares two CComCurrency objects to determine the larger. |
CComCurrency::operator >= |
This operator compares two CComCurrency objects to determine equality or the larger. |
CComCurrency::operator CURRENCY |
Casts a CURRENCY object. |
Name | Description |
---|---|
CComCurrency::m_currency |
The CURRENCY variable created by your class instance. |
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 scaling gives a fixed-point number with 15 digits left of the decimal point and 4 digits to the right. The CURRENCY
data type is 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 consideration is important when dealing with a currency such as the US dollar. Dollar amounts are commonly expressed using only two significant digits after the decimal point. Even though the last two digits aren't 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.
Header: atlcur.h
The constructor.
CComCurrency() throw();
CComCurrency(const CComCurrency& curSrc) throw();
CComCurrency(CURRENCY cySrc) throw();
CComCurrency(DECIMAL dSrc);
CComCurrency(ULONG ulSrc);
CComCurrency(USHORT usSrc);
CComCurrency(CHAR cSrc);
CComCurrency(DOUBLE dSrc);
CComCurrency(FLOAT fSrc);
CComCurrency(LONG lSrc);
CComCurrency(SHORT sSrc);
CComCurrency(BYTE bSrc);
CComCurrency(LONGLONG nInteger, SHORT nFraction);
explicit CComCurrency(LPDISPATCH pDispSrc);
explicit CComCurrency(const VARIANT& varSrc);
explicit CComCurrency(LPCWSTR szSrc);
explicit CComCurrency(LPCSTR szSrc);
curSrc
An existing CComCurrency
object.
cySrc
A variable of type CURRENCY
.
bSrc
, dSrc
, fSrc
, lSrc
, sSrc
, ulSrc
, usSrc
The initial value given to the member variable m_currency
.
cSrc
A character containing the initial value given to the member variable m_currency
.
nInteger
, nFraction
The initial monetary value's integer and fractional components. For more information, see the CComCurrency
overview.
pDispSrc
An IDispatch
pointer.
varSrc
A variable of type VARIANT
. The locale of the current thread is used to perform the conversion.
szSrc
A Unicode or ANSI string containing the initial value. The locale of the current thread is used to perform the conversion.
The constructor sets the initial value of CComCurrency::m_currency
, and accepts a wide range of data types, including integers, strings, floating-point numbers, CURRENCY
variables, and other CComCurrency
objects. If no value is provided, m_currency
is set to 0.
If there's an error, such as an overflow, the constructors lacking an empty exception specification (throw()
) call AtlThrow
with an HRESULT
describing the error.
When using floating-point or double values to assign a value, remember that CComCurrency(10.50)
is equivalent to CComCurrency(10,5000)
, and not CComCurrency(10,50)
.
Returns the address of an m_currency
data member.
CURRENCY* GetCurrencyPtr() throw();
Returns the address of an m_currency
data member
Call this method to return the fractional component of the CComCurrency
object.
SHORT GetFraction() const;
Returns the fractional component of the m_currency
data member.
The fractional component is a 4-digit integer value between -9999 (CY_MIN_FRACTION
) and +9999 (CY_MAX_FRACTION
). GetFraction
returns this value scaled by 10000 (CY_SCALE
). The values of CY_MIN_FRACTION
, CY_MAX_FRACTION
, and CY_SCALE
are defined in atlcur.h.
[!code-cppNVC_ATL_Utilities#50]
Call this method to get the integer component of a CComCurrency
object.
LONGLONG GetInteger() const;
Returns the integer component of the m_currency
data member.
[!code-cppNVC_ATL_Utilities#51]
The CURRENCY
data member.
CURRENCY m_currency;
This member holds the currency accessed and manipulated by the methods of this class.
This operator is used to perform subtraction on a CComCurrency
object.
CComCurrency operator-() const;
CComCurrency operator-(const CComCurrency& cur) const;
cur
A CComCurrency
object.
Returns a CComCurrency
object representing the result of the subtraction. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#55]
This operator compares two objects for inequality.
bool operator!= (const CComCurrency& cur) const;
cur
The CComCurrency
object to be compared.
Returns TRUE
if the item being compared isn't equal to the CComCurrency
object; otherwise, FALSE
.
[!code-cppNVC_ATL_Utilities#56]
This operator is used to perform multiplication on a CComCurrency
object.
CComCurrency operator*(long nOperand) const;
CComCurrency operator*(const CComCurrency& cur) const;
nOperand
The multiplier.
cur
The CComCurrency
object used as the multiplier.
Returns a CComCurrency
object representing the result of the multiplication. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#57]
This operator is used to perform multiplication on a CComCurrency
object and assign it the result.
const CComCurrency& operator*= (long nOperand);
const CComCurrency& operator*= (const CComCurrency& cur);
nOperand
The multiplier.
cur
The CComCurrency
object used as the multiplier.
Returns the updated CComCurrency
object. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#58]
This operator is used to perform division on a CComCurrency
object.
CComCurrency operator/(long nOperand) const;
nOperand
The divisor.
Returns a CComCurrency
object representing the result of the division. If the divisor is 0, an assert failure will occur.
[!code-cppNVC_ATL_Utilities#59]
This operator is used to perform division on a CComCurrency
object and assign it the result.
const CComCurrency& operator/= (long nOperand);
nOperand
The divisor.
Returns the updated CComCurrency
object. If the divisor is 0, an assert failure will occur.
[!code-cppNVC_ATL_Utilities#60]
This operator is used to perform addition on a CComCurrency
object.
CComCurrency operator+(const CComCurrency& cur) const;
cur
The CComCurrency
object to be added to the original object.
Returns a CComCurrency
object representing the result of the addition. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#61]
This operator is used to perform addition on a CComCurrency
object and assign the result to the current object.
const CComCurrency& operator+= (const CComCurrency& cur);
cur
The CComCurrency
object.
Returns the updated CComCurrency
object. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#62]
This operator compares two CComCurrency
objects to determine the lesser.
bool operator<(const CComCurrency& cur) const;
cur
A CComCurrency
object.
Returns TRUE
if the first object is less than the second, FALSE
otherwise.
[!code-cppNVC_ATL_Utilities#63]
This operator compares two CComCurrency
objects to determine equality or the lesser.
bool operator<= (const CComCurrency& cur) const;
cur
A CComCurrency
object.
Returns TRUE
if the first object is less than or equal to the second, FALSE
otherwise.
[!code-cppNVC_ATL_Utilities#64]
This operator assigns the CComCurrency
object to a new value.
const CComCurrency& operator= (const CComCurrency& curSrc) throw();
const CComCurrency& operator= (CURRENCY cySrc) throw();
const CComCurrency& operator= (FLOAT fSrc);
const CComCurrency& operator= (SHORT sSrc);
const CComCurrency& operator= (LONG lSrc);
const CComCurrency& operator= (BYTE bSrc);
const CComCurrency& operator= (USHORT usSrc);
const CComCurrency& operator= (DOUBLE dSrc);
const CComCurrency& operator= (CHAR cSrc);
const CComCurrency& operator= (ULONG ulSrc);
const CComCurrency& operator= (DECIMAL dSrc);
curSrc
A CComCurrency
object.
cySrc
A variable of type CURRENCY
.
sSrc
, fSrc
, lSrc
, bSrc
, usSrc
, dSrc
, cSrc
, ulSrc
, dSrc
The numeric value to assign to the CComCurrency
object.
Returns the updated CComCurrency
object. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#65]
This operator is used to perform subtraction on a CComCurrency
object and assign it the result.
const CComCurrency& operator-= (const CComCurrency& cur);
cur
A CComCurrency
object.
Returns the updated CComCurrency
object. If there's an error, such as an overflow, this operator calls AtlThrow
with an HRESULT
describing the error.
[!code-cppNVC_ATL_Utilities#66]
This operator compares two CComCurrency
objects for equality.
bool operator== (const CComCurrency& cur) const;
cur
The CComCurrency
object to compare.
Returns TRUE
if the objects are equal (that is, the m_currency
data members, both integer and fractional, in both objects have the same value), FALSE
otherwise.
[!code-cppNVC_ATL_Utilities#67]
This operator compares two CComCurrency
objects to determine the larger.
bool operator>(const CComCurrency& cur) const;
cur
A CComCurrency
object.
Returns TRUE
if the first object is greater than the second, FALSE
otherwise.
[!code-cppNVC_ATL_Utilities#68]
This operator compares two CComCurrency
objects to determine equality or the larger.
bool operator>= (const CComCurrency& cur) const;
cur
A CComCurrency
object.
Returns TRUE
if the first object is greater than or equal to the second, FALSE
otherwise.
[!code-cppNVC_ATL_Utilities#69]
These operators are used to cast a CComCurrency
object to a CURRENCY
data type.
operator CURRENCY&() throw();
operator const CURRENCY&() const throw();
Returns a reference to a CURRENCY
object.
[!code-cppNVC_ATL_Utilities#70]
Call this method to round the currency to a specified number of decimal places.
HRESULT Roundint nDecimals);
nDecimals
The number of digits to which m_currency
will be rounded, in the range 0 to 4.
Returns S_OK
on success, or an error HRESULT
on failure.
[!code-cppNVC_ATL_Utilities#52]
Call this method to set the fractional component of a CComCurrency
object.
HRESULT SetFraction(SHORT nFraction);
nFraction
The value to assign to the fractional component of the m_currency
data member. The sign of the fractional component must be the same as the integer component, and the value must be in the range -9999 (CY_MIN_FRACTION
) to +9999 (CY_MAX_FRACTION
).
Returns S_OK
on success, or an error HRESULT
on failure.
[!code-cppNVC_ATL_Utilities#53]
Call this method to set the integer component of a CComCurrency
object.
HRESULT SetInteger(LONGLONG nInteger);
nInteger
The value to be assigned to the integer component of the m_currency
data member. The sign of the integer component must match the sign of the existing fractional component.
nInteger
must be in the range CY_MIN_INTEGER
to CY_MAX_INTEGER
, inclusive. These values are defined in atlcur.h.
Returns S_OK
on success, or an error HRESULT
on failure.
[!code-cppNVC_ATL_Utilities#54]