Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::LookMoney Class Reference

Class representing money. More...

#include <lkmoney.h>

Inheritance diagram for look::LookMoney::

look::LookTypeBase List of all members.

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...

LookTypeBaseGetNewCopy (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...


Detailed Description

Class representing money.

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).


Member Enumeration Documentation

enum look::LookMoney::RoundingScheme
 

How to round.

The results of rounding some numbers are:
2.22.8-2.2-2.8
Nearest 2 3 -2 -3
TowardsZero 2 2 -2 -2
AwayFromZero 3 3 -3 -3
Up 3 3 -2 -2
Down 2 2 -3 -3


Constructor & Destructor Documentation

look::LookMoney::LookMoney ( long thePence = 0 )
 

Constructor.

Parameters:
thePence   Initial value (in pence)
Returns:
None (constructor)


Member Function Documentation

LookString look::LookMoney::GetFullString ( void ) const
 

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.

Returns:
The converted string.

LookTypeBase * look::LookMoney::GetNewCopy ( void ) const [virtual]
 

Get a new copy.

Virtual copy constructor, aka clone.

Returns:
A new copy of this. (You are responsible for deleting it).

Reimplemented from look::LookTypeBase.

long look::LookMoney::GetPence ( void ) const
 

Get value in pence.

Returns:
The value in pence.

double look::LookMoney::GetPounds ( void ) const
 

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.

Returns:
The value in pounds

LookString look::LookMoney::GetSimpleString ( void ) const
 

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.

Returns:
The converted string.

long look::LookMoney::GetTypeID ( void ) const [virtual]
 

Get Type ID.

Pseudo-rtti, or isA.

Returns:
LookMoneyID

Reimplemented from look::LookTypeBase.

bool look::LookMoney::Set ( const LookString & theString )
 

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.

Parameters:
theString   The source string.
Returns:
false if unable to parse (currently never), true otherwise

void look::LookMoney::SetPence ( double thePence )
 

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!)

Parameters:
thePence   The new value.
Returns:
None

void look::LookMoney::SetPence ( long thePence )
 

Set value in pence.

Parameters:
thePence   The new value.
Returns:
None

void look::LookMoney::SetPounds ( double thePounds )
 

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.

Parameters:
thePounds   The new value.
Returns:
None

LookMoney look::LookMoney::operator * ( const LookFloat & theMultiplier ) const
 

Multiply by float.

This rounds to integral pence after the multiplication.

Parameters:
theMultiplier   The multiplier
Returns:
The result

LookMoney look::LookMoney::operator * ( const LookInteger & theMultiplier ) const
 

Multiply by integer.

You can multiply money by an integer or a float. You can't multiply money by money.

Parameters:
theMultiplier   The multiplier
Returns:
The result

LookMoney & look::LookMoney::operator *= ( const LookFloat & theMultiplier )
 

Multiply self by float.

This rounds to integral pence after the multiplication.

Parameters:
theMultiplier   The multiplier
Returns:
The result (*this)

LookMoney & look::LookMoney::operator *= ( const LookInteger & theMultiplier )
 

Multiply self by integer.

Parameters:
theMultiplier   The multiplier
Returns:
The result (*this).

look::LookMoney::operator long ( void ) const
 

Cast to long.

Returns:
Its value in pence.

LookMoney & look::LookMoney::operator= ( long thePence )
 

Assignment from long pence.

Parameters:
thePence   New value (in pence)
Returns:
*this


Member Data Documentation

RoundingScheme look::LookMoney::itsRoundingScheme [static, protected]
 

Initial value:

 
        LookMoney::Nearest
Rounding.

Rounding is used when setting from a double and multiplying by a LookFloat.

See LookMoney::RoundingScheme


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:09 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001