Wt  3.3.9
Public Member Functions | List of all members
Wt::Payment::Money Class Reference

A value class which describes a monetary value. More...

#include <Wt/Payment/Money>

Public Member Functions

 Money ()
 Default constructor. More...
 
 Money (long long value, int cents, const std::string &currency)
 Creates a monetary value. More...
 
long long value () const
 Returns the int part of money. More...
 
int cents () const
 Returns the cents. More...
 
void setCurrency (std::string currency)
 Sets the currency.
 
std::string currency () const
 Returns the currency. More...
 
const std::string toString () const
 Returns a text representation. More...
 
Moneyoperator= (const Money &money)
 Assignment operator.
 
Moneyoperator+= (const Money &money)
 Addition operator. More...
 
Moneyoperator-= (const Money &money)
 Substraction operator. More...
 
Moneyoperator*= (double value)
 Multiplication operator.
 
Moneyoperator/= (double value)
 Division operator.
 
Moneyoperator*= (unsigned value)
 Multiplication operator.
 
Moneyoperator/= (unsigned value)
 Division operator.
 

Detailed Description

A value class which describes a monetary value.

The money is stored in cents as a 64-bit number, which allows for accurate representation for values up to 2^61 - 1, but has as consequence that division will round to the nearest cent.

Math operations on monetary values of different currencies are not allowed and will result in exception.

Constructor & Destructor Documentation

Wt::Payment::Money::Money ( )

Default constructor.

Creates money represent 0 value. This value can be added or substracted safely from any other monetary value (unlike Money(0, 0, "EUR") which would only be safely used in operations involving other money expressed in the Euro currency.

Wt::Payment::Money::Money ( long long  value,
int  cents,
const std::string &  currency 
)

Creates a monetary value.

The value is the integer value, cents is the fractional value (up to 2 digits) expressed in cents (0 - 100) and the currency is a string which indicates the currency.

Member Function Documentation

int Wt::Payment::Money::cents ( ) const

Returns the cents.

Returns the cents - the last 2 digits of value in cents.

std::string Wt::Payment::Money::currency ( ) const

Returns the currency.

See also
setCurrency()
Money & Wt::Payment::Money::operator+= ( const Money money)

Addition operator.

Adding money of different currencies is not allowed.

Money & Wt::Payment::Money::operator-= ( const Money money)

Substraction operator.

Subtracting money of different currencies is not allowed.

const std::string Wt::Payment::Money::toString ( ) const

Returns a text representation.

The format is "value.cents".

long long Wt::Payment::Money::value ( ) const

Returns the int part of money.

Returns the int part of money (money with no cents).


Generated on Tue Nov 21 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11