Project 3 - Currency Type

- Main Page
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | List of all members
currency< T, N > Class Template Reference

`#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)

## Detailed Description

### template<class T = long, int N = 2>
class currency< T, N >

Class to represent a currency value in the global locale.

Definition at line 42 of file currency.hpp.

## Constructor & Destructor Documentation

template<class T = long, int N = 2>

constexpr currency< T, N >::currency | ( | T | integer | ) |
| inline

Initialize the value to `integer`

Parameters

  integer | The integer initial value; the fractional part is zero.

Definition at line 52 of file currency.hpp.

template<class T = long, int N = 2>

currency< T, N >::currency | ( | T | integer,
|  | T | fraction
| ) |  |
| inline

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.

Parameters

  integer | The integer part of the initial value
  fraction | The fractional part of the initial value

Definition at line 59 of file currency.hpp.

template<class T = long, int N = 2>

currency< T, N >::currency | ( | double | value | ) |
| inline

Initialize from a floating point number.

Parameters

  value | the initial value

Definition at line 62 of file currency.hpp.

## Member Function Documentation

template<class T , int N>

std::string currency< T, N >::as_string | ( |  | ) | const

Convert to a string.

Returns
  a string representation of the value, e.g., "$123.04"

Definition at line 150 of file currency.hpp.

template<class T = long, int N = 2>
template<class U >

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 92 of file currency.hpp.

References currency< T, N >::value().

template<class T , int N>

currency< T, N > & currency< T, N >::operator*= | ( | value_type | m | ) |

Multiplication operator.

Parameters

  m | the value to multiply

Returns
  `*this`

Definition at line 178 of file currency.hpp.

template<class T , int N>

currency< T, N > & currency< T, N >::operator*= | ( | int_type | m | ) |

Multiplication operator.

Parameters

  m | the value to multiply

Returns
  `*this`

Definition at line 184 of file currency.hpp.

template<class T , int N>

currency< T, N > & currency< T, N >::operator+= | ( | currency< T, N > | c | ) |

Addition operator.

Parameters

  c | the value to add

Returns
  `*this`

Definition at line 164 of file currency.hpp.

References currency< T, N >::value().

template<class T , int N>

currency< T, N > & currency< T, N >::operator-= | ( | currency< T, N > | c | ) |

Subtraction operator.

Parameters

  c | the value to subtract

Returns
  `*this`

Definition at line 171 of file currency.hpp.

References currency< T, N >::value().

template<class T , int N>

currency< T, N > & currency< T, N >::operator/= | ( | value_type | m | ) |

Division operator.

Parameters

  m | the divisor

Returns
  `*this`

Definition at line 191 of file currency.hpp.

template<class T , int N>

currency< T, N > & currency< T, N >::operator/= | ( | int_type | m | ) |

Division operator.

Parameters

  m | the divisor

Returns
  `*this`

Definition at line 197 of file currency.hpp.

template<class T = long, int N = 2>
template<class Char , class Traits >

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.

Parameters

  strm | Input stream

Returns
  true if the read is success and `*this` has been modified, or false if the read fails. Check `strm` for details.

Referenced by operator>>().

The documentation for this class was generated from the following file:

- currency.hpp