Project 3 - Currency Type
|
#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 | |
constexpr | currency () |
Default constructor initializes the value to zero. | |
constexpr | 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. More... | |
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. | |
template<class CharT , class Traits > | |
bool | read (std::basic_istream< CharT, Traits > &strm) |
Class to represent a currency value in the global locale.
Definition at line 42 of file currency.hpp.
Initialize the value to integer
integer | The integer initial value; the fractional part is zero. |
Definition at line 52 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 59 of file currency.hpp.
Initialize from a floating point number.
value | the initial value |
Definition at line 62 of file currency.hpp.
std::string currency< T, N >::as_string | ( | ) | const |
Convert to a string.
Definition at line 150 of file currency.hpp.
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 92 of file currency.hpp.
References currency< T, N >::value().
currency< T, N > & currency< T, N >::operator*= | ( | value_type | m | ) |
Multiplication operator.
m | the value to multiply |
*this
Definition at line 178 of file currency.hpp.
Multiplication operator.
m | the value to multiply |
*this
Definition at line 184 of file currency.hpp.
Addition operator.
c | the value to add |
*this
Definition at line 164 of file currency.hpp.
References currency< T, N >::value().
Subtraction operator.
c | the value to subtract |
*this
Definition at line 171 of file currency.hpp.
References currency< T, N >::value().
currency< T, N > & currency< T, N >::operator/= | ( | value_type | m | ) |
Division operator.
m | the divisor |
*this
Definition at line 191 of file currency.hpp.
Division operator.
m | the divisor |
*this
Definition at line 197 of file currency.hpp.
bool currency< T, N >::read | ( | std::basic_istream< Char, Traits > & | strm | ) |
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. Referenced by operator>>().