{"id":3189,"date":"2018-11-13T20:15:46","date_gmt":"2018-11-13T18:15:46","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=3189"},"modified":"2018-11-13T15:53:34","modified_gmt":"2018-11-13T13:53:34","slug":"moneycpp-a-cpp-library-for-handling-monetary-values","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/","title":{"rendered":"moneycpp &#8211; a C++ library for handling monetary values"},"content":{"rendered":"<p>I have been working lately on a C++ library for handling monetary values, currencies, rounding and other related features. It is called moneycpp and it&#8217;s a C++ 17 header-only, cross-platform library available on <a href=\"https:\/\/github.com\/mariusbancila\/moneycpp\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>.<\/p>\n<p>The library is intended for being used in a variety of types of application including ERP systems, banking, finance, insurance, games, and others.<\/p>\n<p>The following is a list of its core requirements:<\/p>\n<p><!-- more --><\/p>\n<ul>\n<li>Provide an API for handling and calculating with monetary amounts.<\/li>\n<li>Support different numeric capabilities.<\/li>\n<li>Provide a default set of rounding algorithms and policies and support additional user-defined ones.<\/li>\n<li>Support the entire <a href=\"https:\/\/en.wikipedia.org\/wiki\/ISO_4217\" target=\"_blank\">ISO 4217<\/a> list of currencies.<\/li>\n<li>Support the entire <a href=\"https:\/\/en.wikipedia.org\/wiki\/ISO_3166-1\" target=\"_blank\">ISO 3166-1<\/a> list of countries.<\/li>\n<li>It should be possible for users to add new (virtual) currencies and countries.<\/li>\n<\/ul>\n<h3>Overview<\/h3>\n<p>The library is built around several core components:<\/p>\n<ul>\n<li><tt>money<\/tt> that holds a monetary value<\/li>\n<li><tt>currency_unit<\/tt> that contains currency information for a monetary value as per <a href=\"https:\/\/en.wikipedia.org\/wiki\/ISO_4217\" target=\"_blank\">ISO 4217<\/a><\/li>\n<li><tt>country_unit<\/tt> that contains country information in relation to currencies, as per <a href=\"https:\/\/en.wikipedia.org\/wiki\/ISO_3166-1\" target=\"_blank\">ISO 3166-1<\/a><\/li>\n<li>rounding algorithms &#8211; that specify how values are rounded, and policies &#8211; that specify how monetary values are rounded using a rounding algorithm<\/li>\n<\/ul>\n<h3>Monetary values<\/h3>\n<p>A monetary value has two dimensions: the actual amount and the currency that it represents. A monetary value is represented by the <tt>money<\/tt> class. The following are examples of working with monetary values:<\/p>\n<pre class=\"lang:c++ decode:true \">\/\/ create and operate with money values\r\nauto m = make_money(20.0, currency::USD);\r\nm += make_money(10.5, currency::USD);\r\nm *= 2.5;\r\n\r\n\/\/ round money values\r\nm = rounding_policy_standard(round_ceiling())(m);\r\n\r\n\/\/ convert between currencies \r\nauto ex = exchange_money(\r\n   m, \r\n   currency::EUR, 0.86,\r\n   rounding_policy_standard(round_ceiling()));<\/pre>\n<p>The examples above use the type <tt>double<\/tt> for numerical values. This is a floating point type and can only represent exact decimal values for numbers that are a sum of inverse powers of two. That means floating point types can exactly represent values such as 0.5, 1.25, or 42.90625 but cannot do the same for values such as 0.10 or 19.99. Therefore, floating point types are not appropriate for monetary values because they cannot exactly represent most real numbers. This can be an important aspect in financial applications or, in general, in applications that deal with monetary transactions because over time, or over a large number of transactions, the small differences can add up to important values. Because of this, the library supports 3rd party libraries that provide better representations of real numbers, such as <tt>boost::multiprecision<\/tt>. All the rounding algorithms are specialized for the <tt>boost::multiprecision::cpp_dec_float<\/tt>, aliased as <tt>decimal<\/tt>, as shown below.<\/p>\n<pre class=\"lang:c++ decode:true \">using decimal = boost::multiprecision::number&lt;boost::multiprecision::cpp_dec_float&lt;50&gt;&gt;;\r\n\r\ninline decimal operator\"\"_dec(char const * str, std::size_t)\r\n{ return decimal(str); }\r\n\r\nauto m = make_money(\"20.99\"_dec, currency::USD);\r\n\r\nauto ex = exchange_money(\r\n   m, \r\n   currency::EUR, \"0.8649\"_dec,\r\n   rounding_policy_to_currency_digits(round_half_even()));<\/pre>\n<h3>Countries and Currencies<\/h3>\n<p>The library provides a full database of ISO recognized countries and currencies and functions to look them up. Information about a country is represented by the <tt>country_unit<\/tt> class and information about a currency by the <tt>currency_unit<\/tt> class. Below are several examples for searching these lists:<\/p>\n<pre class=\"lang:c++ decode:true \">\/\/ finding a currency\r\nauto cu1 = find_currency(\"EUR\");\r\nauto cu2 = find_currency(978);\r\nassert(cu1 == cu2);\r\nassert(cu1 == currency::EUR);\r\nassert(cu1.value().code == \"EUR\");\r\n\r\n\/\/ finding a country\r\nauto cu1 = find_country(\"US\");\r\nauto cu2 = find_country(840);\r\nassert(cu1 == cu2);\r\nassert(cu1 == country::US);\r\nassert(cu1.value().alpha2 == \"US\")\r\n\r\n\/\/ finding the (main) currency of a country\r\nauto cu1 = country::find_country_currency(country::RO);\r\nassert(cu1 == currency::RON);\r\n\r\nauto cu2 = country::find_country_currency(country::US);\r\nassert(cu2 == currency::USD);\r\n\r\n\/\/ finding all the currencies from a country as a set\r\nauto s = country::find_country_currencies(country::US);\r\nassert(s.size() == 2);\r\nassert(*s.begin() == currency::USD);\r\nassert(*std::next(s.begin()) == currency::USN);\r\n\r\n\/\/ finding all the currencies from a country as a range\r\nauto r = country::country_currency_equal_range(country::currencies, country::US);\r\nassert(std::distance(r.first, r.second) == 2);\r\nassert(r.first-&gt;second == currency::USD);\r\nassert(std::next(r.first)-&gt;second == currency::USN);<\/pre>\n<p>The built-in databases for countries, currencies, and country currencies (available when the <tt>HAS_COUNTRY_AND_CURRENCY_DB<\/tt> macro is defined) can be extended with additional units. In this case, you can use overloaded versions of these functions that use iterators to define the range to search. The following example shows how to do so with the currencies database, but the same apply for countries (<tt>find_country()<\/tt> overload) and country currencies (<tt>find_country_currencies()<\/tt> and <tt>country_currency_equal_range()<\/tt> overloads):<\/p>\n<pre class=\"lang:c++ decode:true \">std::vector&lt;currency_unit&gt; my_currencies{ currency::currencies };\r\nmy_currencies.emplace_back(currency_unit{ \"VIR\", 1001, 2, \"Virtual Currency\" });\r\n\r\nauto cu1 = find_currency(std::cbegin(my_currencies), std::cend(my_currencies), \"VIR\");\r\nauto cu2 = find_currency(std::cbegin(my_currencies), std::cend(my_currencies), 1001);\r\n\r\nassert(cu1 != std::cend(my_currencies));\r\nassert(cu1 == cu2);\r\nassert(cu1-&gt;alpha2 == \"VIR\");<\/pre>\n<h3>Rounding<\/h3>\n<p>Several rounding algorithms are provided with the library. These algorithms transform a numerical value from a greater precision (e.g. 19.99128) to a lesser precision (e.g. 19.99). In addition to these, any user-defined rounding algorithm can be used with the library. The rounding algorithms, implemented as functors, are as follows:<\/p>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Description<\/th>\n<th>Functor<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>None<\/td>\n<td>no rounding<\/td>\n<td><tt>round_none<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Up<\/td>\n<td>rounds away from zero<\/td>\n<td><tt>round_up<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Down<\/td>\n<td>rounds towards zero<\/td>\n<td><tt>round_down<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Ceiling<\/td>\n<td>rounds towards positive infinity<\/td>\n<td><tt>round_ceiling<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Floor<\/td>\n<td>rounds towards negative infinity<\/td>\n<td><tt>round_floor<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Half up<\/td>\n<td>rounds towards &#8220;nearest neighbour&#8221; unless both neighbours are equidistant, in which case round up<\/td>\n<td><tt>round_half_up<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Half down<\/td>\n<td>rounds towards &#8220;nearest neighbour&#8221; unless both neighbours are equidistant, in which case round down<\/td>\n<td><tt>round_half_down<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Half even<\/td>\n<td>rounds towards the &#8220;nearest neighbour&#8221; unless both neighbours are equidistant, in which case, round towards the even neighbour<\/td>\n<td><tt>round_half_even<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Half odd<\/td>\n<td>rounds towards the &#8220;nearest neighbour&#8221; unless both neighbours are equidistant, in which case, round towards the odd neighbour<\/td>\n<td><tt>round_half_odd<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The following is a table with numerical examples for each rounding algorithm:<\/p>\n<table>\n<thead>\n<tr>\n<th>Algorithm \/ Value<\/th>\n<th>-5.5<\/th>\n<th>-2.5<\/th>\n<th>-1.6<\/th>\n<th>-1.1<\/th>\n<th>-1.0<\/th>\n<th>1.0<\/th>\n<th>1.1<\/th>\n<th>1.6<\/th>\n<th>2.5<\/th>\n<th>5.5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Up<\/td>\n<td>-6.0<\/td>\n<td>-3.0<\/td>\n<td>-2.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>2.0<\/td>\n<td>3.0<\/td>\n<td>6.0<\/td>\n<\/tr>\n<tr>\n<td>Down<\/td>\n<td>-5.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>5.0<\/td>\n<\/tr>\n<tr>\n<td>Ceiling<\/td>\n<td>-5.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>2.0<\/td>\n<td>3.0<\/td>\n<td>6.0<\/td>\n<\/tr>\n<tr>\n<td>Floor<\/td>\n<td>-6.0<\/td>\n<td>-3.0<\/td>\n<td>-2.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>5.0<\/td>\n<\/tr>\n<tr>\n<td>Half up<\/td>\n<td>-6.0<\/td>\n<td>-3.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>3.0<\/td>\n<td>6.0<\/td>\n<\/tr>\n<tr>\n<td>Half down<\/td>\n<td>-5.0<\/td>\n<td>-2.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>2.0<\/td>\n<td>5.0<\/td>\n<\/tr>\n<tr>\n<td>Half even<\/td>\n<td>-6.0<\/td>\n<td>-2.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>2.0<\/td>\n<td>6.0<\/td>\n<\/tr>\n<tr>\n<td>Half odd<\/td>\n<td>-5.0<\/td>\n<td>-3.0<\/td>\n<td>-2.0<\/td>\n<td>-1.0<\/td>\n<td>-1.0<\/td>\n<td>1.0<\/td>\n<td>1.0<\/td>\n<td>2.0<\/td>\n<td>3.0<\/td>\n<td>5.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>More about these rounding algorithms can be found in the article <a href=\"https:\/\/www.eetimes.com\/document.asp?doc_id=1274515\" target=\"_blank\">Rounding Algorithms 101 Redux<\/a>.<\/p>\n<p>Apart from the rounding algorithms, the library provides several rounding policies that define how a money value should be rounded. The available policies are:<\/p>\n<table>\n<thead>\n<tr>\n<th>Type name<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><tt>rounding_policy_none<\/t><\/td>\n<td>No rounding is performed<\/td>\n<\/tr>\n<tr>\n<td><tt>rounding_policy_standard<\/tt><\/td>\n<td>Rounding to 4 decimal digits<\/td>\n<\/tr>\n<tr>\n<td><tt>rounding_policy_to_currency_digits<\/tt><\/td>\n<td>Rounding to the number of digits (i.e. minor unit) as defined for the currency<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Any additional user-defined policy can be used instead of the ones supplied with the library.<\/p>\n<h3>Using the library<\/h3>\n<p>The library is composed of several headers and uses C++ 17 features (such as <tt>string_view<\/tt>, <tt>optional<\/tt>, structured bindings). You need a compiler that supports these features.<\/p>\n<p>The library works with:<\/p>\n<ul>\n<li>the built-in floating point types <tt>float<\/tt>, <tt>double<\/tt>, and <tt>long double<\/tt> (NOT ADVICED!)<\/li>\n<li><tt>boost::multiprecision<\/tt> library, with particular specializations for <tt>boost::multiprecision::cpp_dec_float&lt;50&gt;<\/tt>, aliased as decimal<\/li>\n<li>any 3rd library provided that you specialize the rounding function object templates<\/li>\n<\/ul>\n<p>To include the full library of ISO specified currencies and countries you must define the macro <tt>HAS_COUNTRY_AND_CURRENCY_DB<\/tt>.<\/p>\n<p>In order to use <tt>boost::multiprecision<\/tt> you must:<\/p>\n<ul>\n<li>define the macro <tt>HAS_BOOST_MULTIPRECISION<\/tt><\/li>\n<li>make the path to the boost headers available in the include search path<\/li>\n<\/ul>\n<p>In order to use <tt>boost::optional<\/tt> instead of <tt>std::optional<\/tt> you must:<\/p>\n<ul>\n<li>define the macro <tt>HAS_BOOST_OPTIONAL<\/tt><\/li>\n<li>make the path to the boost headers available in the include search path<\/li>\n<li>make the path to the boost library files available for the libraries search path<\/li>\n<\/ul>\n<p>The library is accompanied by unit tests (built with <a href=\"https:\/\/github.com\/catchorg\/Catch2\/\" target=\"_blank\">Catch2<\/a>). CMake is used for creating projects to build and run the unit tests. You can do the following to build it with support for <tt>boost::multiprecision<\/tt>:<\/p>\n<ul>\n<li>clone or download and unzip the <tt>moneycpp<\/tt> library<\/li>\n<li>create a folder called `build`<\/li>\n<li>download and unzip <a href=\"https:\/\/www.boost.org\/\" target=\"_blank\">Boost<\/a><\/li>\n<li>run CMake from the `build` folder<\/li>\n<li>open the project in the IDE (such as Visual Studio or Xcode), build the project, and run it<\/li>\n<\/ul>\n<p>Here is an example for creating a project for VS2017 with boost available at <tt>C:\\libraries\\boost_1_68_0\\<\/tt> (make sure to include the trailing <tt>\\<\/tt>).<\/p>\n<pre class=\"lang:default decode:true \">\r\nmkdir build\r\ncd build\r\ncmake .. -G \"Visual Studio 15 2017\" -DCOUNTRY_AND_CURRENCY_DB=ON -DBOOST_MULTIPRECISION=ON -DBOOST_INCLUDE_DIR=C:\\libraries\\boost_1_68_0\\\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have been working lately on a C++ library for handling monetary values, currencies, rounding and other related features. It is called moneycpp and it&#8217;s a C++ 17 header-only, cross-platform library available on <a href=\"https:\/\/github.com\/mariusbancila\/moneycpp\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>.<\/p>\n<p>The library is intended for being used in a variety of types of application including ERP systems, banking, finance, insurance, games, and others.<\/p>\n<p>The following is a list of its core requirements:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,1],"tags":[451,475,491,138,568],"class_list":["post-3189","post","type-post","status-publish","format-standard","hentry","category-c","category-uncategorized","tag-c","tag-c17","tag-github","tag-library","tag-money"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,c++17,github,library,money\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"moneycpp \u2013 a C++ library for handling monetary values\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2018-11-13T18:15:46+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2018-11-13T13:53:34+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"moneycpp \u2013 a C++ library for handling monetary values\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#article\",\"name\":\"moneycpp \\u2013 a C++ library for handling monetary values\",\"headline\":\"moneycpp &#8211; a C++ library for handling monetary values\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2018-11-13T20:15:46+02:00\",\"dateModified\":\"2018-11-13T15:53:34+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#webpage\"},\"articleSection\":\"C++, Uncategorized, C++, C++17, github, library, money\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#listItem\",\"name\":\"moneycpp &#8211; a C++ library for handling monetary values\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#listItem\",\"position\":5,\"name\":\"moneycpp &#8211; a C++ library for handling monetary values\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/\",\"name\":\"moneycpp \\u2013 a C++ library for handling monetary values\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2018\\\/11\\\/13\\\/moneycpp-a-cpp-library-for-handling-monetary-values\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2018-11-13T20:15:46+02:00\",\"dateModified\":\"2018-11-13T15:53:34+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"moneycpp \u2013 a C++ library for handling monetary values","description":"","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/","robots":"max-image-preview:large","keywords":"c++,c++17,github,library,money","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#article","name":"moneycpp \u2013 a C++ library for handling monetary values","headline":"moneycpp &#8211; a C++ library for handling monetary values","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2018-11-13T20:15:46+02:00","dateModified":"2018-11-13T15:53:34+02:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#webpage"},"articleSection":"C++, Uncategorized, C++, C++17, github, library, money"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#listItem","name":"moneycpp &#8211; a C++ library for handling monetary values"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#listItem","position":5,"name":"moneycpp &#8211; a C++ library for handling monetary values","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/","name":"moneycpp \u2013 a C++ library for handling monetary values","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2018-11-13T20:15:46+02:00","dateModified":"2018-11-13T15:53:34+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"moneycpp \u2013 a C++ library for handling monetary values","og:url":"https:\/\/mariusbancila.ro\/blog\/2018\/11\/13\/moneycpp-a-cpp-library-for-handling-monetary-values\/","article:published_time":"2018-11-13T18:15:46+00:00","article:modified_time":"2018-11-13T13:53:34+00:00","twitter:card":"summary","twitter:title":"moneycpp \u2013 a C++ library for handling monetary values"},"aioseo_meta_data":{"post_id":"3189","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:04:15","updated":"2025-12-12 07:51:30","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":1,"uagb_excerpt":"I have been working lately on a C++ library for handling monetary values, currencies, rounding and other related features. It is called moneycpp and it's a C++ 17 header-only, cross-platform library available on GitHub. The library is intended for being used in a variety of types of application including ERP systems, banking, finance, insurance, games,&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">Uncategorized<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">Uncategorized<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">C++17<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">github<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">library<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">money<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">C++17<\/span>","<span class=\"advgb-post-tax-term\">github<\/span>","<span class=\"advgb-post-tax-term\">library<\/span>","<span class=\"advgb-post-tax-term\">money<\/span>"]}},"comment_count":"1","relative_dates":{"created":"Posted 8 years ago","modified":"Updated 8 years ago"},"absolute_dates":{"created":"Posted on November 13, 2018","modified":"Updated on November 13, 2018"},"absolute_dates_time":{"created":"Posted on November 13, 2018 8:15 pm","modified":"Updated on November 13, 2018 3:53 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-Pr","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=3189"}],"version-history":[{"count":9,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3189\/revisions"}],"predecessor-version":[{"id":3199,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3189\/revisions\/3199"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=3189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=3189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=3189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}