#include <currency.hpp>
Public Types | |
typedef T | int_type |
Storage type. | |
typedef fixed< T, N > | value_type |
Type of the actual value. | |
Public Member Functions | |
currency () | |
Default constructor initializes the value to zero. | |
currency (T integer) | |
currency (T integer, T fraction) | |
currency (double value) | |
template<class U, int M> | |
currency (currency< U, M > const &rhs) | |
Copy a value that uses a different precision. | |
template<class U, int M> | |
currency & | operator= (currency< U, M > rhs) |
Assign a value that uses a different precision. | |
std::string | as_string () const |
template<class Char, class Traits> | |
bool | read (std::basic_istream< Char, Traits > &strm) |
template<class U> | |
U | convert () const |
Convert to some other type, especially floating point. | |
int_type | round () const |
Round off to the nearest integer, using banker's rounding. | |
int_type | integer () const |
Return the integer part (which is the same as trunc()). | |
template<int M> | |
int_type | fraction () const |
Return the fractional part, to M places. | |
int_type | fraction () const |
Return the fractional part. | |
currency & | operator+= (currency c) |
currency & | operator-= (currency c) |
currency & | operator *= (value_type m) |
currency & | operator *= (int_type m) |
currency & | operator/= (value_type m) |
currency & | operator/= (int_type m) |
void | negate () |
Negate this value. | |
currency & | operator++ () |
Pre-increment operator. | |
currency | operator++ (int) |
Post-increment operator. | |
currency & | operator-- () |
Pre-decrement operator. | |
currency | operator-- (int) |
Post-decrement operator. | |
value_type | value () const |
Return the internal value. |
Definition at line 22 of file currency.hpp.
Initialize the value to integer
integer | The integer initial value; the fractional part is zero. |
Definition at line 32 of file currency.hpp.
Initialize the value. The interpretation of the fractional part depends on N
. For example, if N
is 2, a fraction
of 9 represents 0.09, buf if N
is 5, fraction
of 9 means 0.0009.
integer | The integer part of the initial value | |
fraction | The fractional part of the initial value |
Definition at line 39 of file currency.hpp.
Initialize from a floating point number.
value | the initial value |
Definition at line 42 of file currency.hpp.
std::string currency< T, N >::as_string | ( | ) | const [inline] |
Convert to a string.
Definition at line 130 of file currency.hpp.
References currency< T, N >::fraction(), currency< T, N >::integer(), and fixed< T, N >::places.
bool currency< T, N >::read | ( | std::basic_istream< CharT, Traits > & | strm | ) | [inline] |
Overwrite this value with the value read from the stream. The value in the stream must have the correct number of digits. If the showbase flag is set, the currency symbol must be present.
strm | Input stream |
*this
has been modified, or false if the read fails. Check strm
for details. Definition at line 221 of file currency.hpp.
References currency< T, N >::fraction(), currency< T, N >::integer(), and fixed< T, N >::read().
Referenced by operator>>().
U currency< T, N >::convert | ( | ) | const [inline] |
Convert to some other type, especially floating point.
Convert the value to a different numeric type. Typically, the other type is a floating-point type.
Definition at line 72 of file currency.hpp.
References currency< T, N >::value().
currency< T, N > & currency< T, N >::operator+= | ( | currency< T, N > | c | ) | [inline] |
Addition operator.
c | the value to add |
*this
Definition at line 144 of file currency.hpp.
References currency< T, N >::value().
currency< T, N > & currency< T, N >::operator-= | ( | currency< T, N > | c | ) | [inline] |
Subtraction operator.
c | the value to subtract |
*this
Definition at line 151 of file currency.hpp.
References currency< T, N >::value().
currency< T, N > & currency< T, N >::operator *= | ( | value_type | m | ) | [inline] |
Multiplication operator.
m | the value to multiply |
*this
Definition at line 158 of file currency.hpp.
Multiplication operator.
m | the value to multiply |
*this
Definition at line 164 of file currency.hpp.
currency< T, N > & currency< T, N >::operator/= | ( | value_type | m | ) | [inline] |
Division operator.
m | the divisor |
*this
Definition at line 171 of file currency.hpp.
Division operator.
m | the divisor |
*this
Definition at line 177 of file currency.hpp.