Wt  4.11.1
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.h>

Public Member Functions

 Money ()
 Default constructor. More...
 
 Money (long long value, int cents, const std::string &currency)
 Creates a monetary value. More...
 
 Money (const Money &other)
 Copy constructor.
 
 ~Money ()=default
 Destructor.
 
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

◆ Money() [1/2]

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.

◆ Money() [2/2]

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

◆ cents()

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

Returns the cents.

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

◆ currency()

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

Returns the currency.

See also
setCurrency()

◆ operator+=()

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

Addition operator.

Adding money of different currencies is not allowed.

◆ operator-=()

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

Substraction operator.

Subtracting money of different currencies is not allowed.

◆ toString()

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

Returns a text representation.

The format is "value.cents".

◆ value()

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

Returns the int part of money.

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