currencygithub.com/castedo/isomon

Currency Library

Features

Class currency

The easiest way to use the isomon::currency class is to copy this single unified header: isomon_currency.hpp.

If you want to edit the files or build unit or performance tests, you should make a clone of the git source code repository

Table 1. Example Values of isomon::currency

str()

isonum()

num_minors()

Comments

"XXX"

999

0

ISO 4217 "No currency" code; default value.

"EUR"

978

100

Euros

"USD"

840

100

US Dollars

"JPY"

392

1

Japanese Yen

"XAU"

959

0

Gold

"XFU"

0

0

settlement currency of the International Union of Railways


Although most currencies have a number of minor units, some do not and thus return 0 from method num_minors(). Notably this is the case for the special “currency” XXX which stands for “no currency”.

The ISO 4217 standard specifies that “Nil” is the “numeric” code of XFU, a settlement currency of the International Union of Railways. The isomon library maps this to the integer 0.

C++ header for currency class.

namespace isomon {
  class currency;

  // Output ISO alphabetic code (3 Latin letters) 
  std::ostream & operator<<(std::ostream & os, currency rhs);

  // Read ISO alphabetic code (3 Latin letters) 
  std::istream & operator>>(std::istream & is, currency & rhs);
}

Low-level C functions

For C99 programmers or C++ programmers who want to implement their own currency class, the low-level C function interface provide access to all the ISO 4217 data and almost all the functionality of the isomon::currency class (which is a thin type-safe wrapper around these C functions).

Currency low-level C functions.

namespace isomon {
  typedef int16_t isonum_t;

  const size_t isonum_count;  // Number of possible ISO numeric code values this library will handle. 
  namespace data {
    bool code2hash(const char *, int16_t *);
    void hash2code(int16_t, char *);
    bool hash2isonum(int16_t, isonum_t *);
    int16_t isonum2hash(isonum_t);
    bool code2isonum(const char *, isonum_t *);
    const char * isonum2code(isonum_t);
    bool is_isonum(int16_t);
    int8_t num_minor_digits(isonum_t);
    int16_t num_minors(isonum_t);
    bool add_currency(int16_t, const char *);
    bool set_num_minors(int16_t, int16_t, int8_t);
  }
}

Other Currency Classes

Acknowledgements

  • to Remi Chateauneu, author of the ccy library, for valuable comments and discussion
  • to Designomotion for a more attractive logo