Wt
4.11.1
|
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 ¤cy) | |
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... | |
Money & | operator= (const Money &money) |
Assignment operator. | |
Money & | operator+= (const Money &money) |
Addition operator. More... | |
Money & | operator-= (const Money &money) |
Substraction operator. More... | |
Money & | operator*= (double value) |
Multiplication operator. | |
Money & | operator/= (double value) |
Division operator. | |
Money & | operator*= (unsigned value) |
Multiplication operator. | |
Money & | operator/= (unsigned value) |
Division operator. | |
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.
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.
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.
Addition operator.
Adding money of different currencies is not allowed.
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).