#include <lkmoney.h>
Inheritance diagram for look::LookMoney::
Public Types | |
enum | RoundingScheme { Nearest = 0, TowardsZero, AwayFromZero, Up, Down } |
How to round. More... | |
Public Methods | |
LookMoney (long thePence=0) | |
Constructor. More... | |
~LookMoney (void) | |
Destructor. | |
LookMoney (const LookMoney &theOther) | |
Copy constructor. | |
LookMoney& | operator= (const LookMoney &theOther) |
Assignment operator. | |
LookMoney& | operator= (long thePence) |
Assignment from long pence. More... | |
operator long (void) const | |
Cast to long. More... | |
LookTypeBase* | GetNewCopy (void) const |
Get a new copy. More... | |
long | GetTypeID (void) const |
Get Type ID. More... | |
void | SetPence (long thePence) |
Set value in pence. More... | |
long | GetPence (void) const |
Get value in pence. More... | |
void | SetPence (double thePence) |
Set value in pence. More... | |
void | SetPounds (double thePounds) |
Set value in pounds. More... | |
double | GetPounds (void) const |
Get value in pounds. More... | |
bool | Set (const LookString &theString) |
Set from a string. More... | |
LookString | GetSimpleString (void) const |
Convert to a simple string. More... | |
LookString | GetFullString (void) const |
Convert to a more complex string. More... | |
bool | operator== (const LookMoney &theValue) const |
Equal. | |
bool | operator!= (const LookMoney &theValue) const |
Not equal. | |
bool | operator<= (const LookMoney &theValue) const |
Less than or equal. | |
bool | operator>= (const LookMoney &theValue) const |
Greater than or equal. | |
bool | operator< (const LookMoney &theValue) const |
Less than. | |
bool | operator> (const LookMoney &theValue) const |
Greater than. | |
LookMoney | operator+ (const LookMoney &theValue) const |
Addition. | |
LookMoney& | operator+= (const LookMoney &theValue) |
Addition. | |
LookMoney | operator- (const LookMoney &theValue) const |
Subtraction. | |
LookMoney& | operator-= (const LookMoney &theValue) |
Subtraction. | |
LookMoney | operator * (const LookInteger &theMultiplier) const |
Multiply by integer. More... | |
LookMoney& | operator *= (const LookInteger &theMultiplier) |
Multiply self by integer. More... | |
LookMoney | operator * (const LookFloat &theMultiplier) const |
Multiply by float. More... | |
LookMoney& | operator *= (const LookFloat &theMultiplier) |
Multiply self by float. More... | |
Static Public Methods | |
RoundingScheme | GetRoundingScheme (void) |
Get itsRoundingScheme. | |
void | SetRoundingScheme (RoundingScheme theRoundingScheme) |
Set itsRoundingScheme. | |
Protected Attributes | |
long | itsPence |
Value in pence. | |
Static Protected Attributes | |
RoundingScheme | itsRoundingScheme |
Rounding. More... |
This class represents money.
It stores its value as integral pence to avoid floating point errors.
It may appear UK-specific, with talk of pounds and pence, but there is nothing to stop it being used for other currencies with units of x and x/100. (eg dollar, franc, etc).
|
How to round. The results of rounding some numbers are:
|
|
Constructor.
|
|
Convert to a more complex string. This is like GetSimpleString() except it puts commas between every three places. The format is eg '10,030.34' or '-10,030.25'. If you want a european-formatted '10.030,34', you'll have to sort that out somewhere else.
|
|
Get a new copy. Virtual copy constructor, aka clone.
Reimplemented from look::LookTypeBase. |
|
Get value in pence.
|
|
Get value in pounds. Get the value in pounds (a double). Given the problems of floating-point currency, I don't recommend that you use it.
|
|
Convert to a simple string. The format is eg '10030.34' or '-10030.25'. If you want a european-formatted '10030,34', you'll have to sort that out somewhere else.
|
|
Get Type ID. Pseudo-rtti, or isA.
Reimplemented from look::LookTypeBase. |
|
Set from a string. It ignores all characters apart from -, . and 0-9. It is quite stupid, eg it will convert '-24,2-32.424.223-' into -24232.42.
|
|
Set value in pence. Set the value in pence from a double. (Used eg after multiplying a quantity by a price). The rounding depends on itsRoundingScheme (GetRoundingScheme(), SetRoundingScheme()). Nearest (add 0.5 then floor()) may not work for half-pence. You may need to add a very small value to correct this - this will depend on the original precision. (Eg quantity * price. Quantity an hence net result is 3dp, so adding 0.0001 will mean that 18.499 stays at 18 and 18.500 will definitely be rounded to 19. The main lesson is that floating point numbers don't mix with currency!)
|
|
Set value in pence.
|
|
Set value in pounds. Set the value in pounds from a double. DbField uses this where the database returns floating-point currency, but I don't encourage you to. See SetPence() for rounding comments.
|
|
Multiply by float. This rounds to integral pence after the multiplication.
|
|
Multiply by integer. You can multiply money by an integer or a float. You can't multiply money by money.
|
|
Multiply self by float. This rounds to integral pence after the multiplication.
|
|
Multiply self by integer.
|
|
Cast to long.
|
|
Assignment from long pence.
|
|
Initial value: LookMoney::Nearest Rounding is used when setting from a double and multiplying by a LookFloat. |