Pecunia 0.9.0-alpha.22
Library using the ISO-4217 currency standard & a fixed monetary unit size
Loading...
Searching...
No Matches
README

STATUS Latest Release coverage report

                          DESCRIPTION

Pecunia is a C++ currency library using the ISO-4217 standard. Its three priorities are: 1) Safe to use, e.g. prevent common money errors from happening. 2) Simple to use, e.g. reading the code should be clear in its purpose. 3) Efficient in speed, e.g. adding two of the currencies should be as near to a raw, weak type like float or int as possible. The order of priorities are listed in the order of importance.

In addition to the Wiki, more information is found at:

                        BUILD ENVIRONMENT

Pecunia is mainly developed on Mageia and Fedora using just the standard development libraries, KDE, and QT. It is also tested on Debian, macOS, and Microsoft Windows.

                          DIRECTORY MAP

All the source code is listed in the src directory. Installation instructions can be found in the INSTALL file. For a listing of all the contributors to Pecunia you can find that information in the CREDITS file. All the current news can be be found on the main website.

                          EXAMPLES

Once compiled you can link it into your projects and do some of the examples below.

Add Two Currencies:

Money pop{Currency::USD, 1, 25u};
Money candy{Currency::USD, 0, 75u};
Money sum{pop + candy}; // Sum now holds 2 USD.
Money sum(const Currency &accumulateIn, const Container &elements, const std::optional< std::function< Money(const typename Container::value_type &)> > &mutator=std::nullopt)
Sums up a collection of monetary values, potentially transformed by a user-defined mutator function,...

Add Two Different Currencies:

setUpLibrary(&exchangeRates); // The exchangeRates function is user supplied.
// ...
Money account1{Currency::USD, 1, 25u};
Money account2{Currency::PLN, 0, 75u};
Money sum{account1 + account2};
// The sum holds 1.42 USD when the exchangeRates function returns the rate of 1 PLN = 0.23 USD.
// This is because addition is left associative and will use the currency of the "USD" object.

Add Two Different Currencies & Store In a Third:

setUpLibrary(&exchangeRates);
// ...
Money account1{Currency::USD, 1, 25u};
Money account2{Currency::PLN, 0, 75u};
Money account3{Currency::EUR};
account3 = account1 + account2;
// The account3 holds 1.30 EUR when the exchangeRates function returns the rate of
// 1 EUR = 0.92 USD. This is because addition is left associative and will use the currency of
// the "USD" object. The sum is then converted and stored into the "EUR" as the assignment
// operator is left associative.