lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] valyuta/002 420fac7 08/14: Allow currency to be doll


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 420fac7 08/14: Allow currency to be dollars rather than cents
Date: Thu, 17 Sep 2020 16:27:15 -0400 (EDT)

branch: valyuta/002
commit 420fac7eccb1018f71c0f2efb5bb51754b19b0f3
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Allow currency to be dollars rather than cents
    
    Dollars and hundredths requires a floating-point currency::data_type.
    Writing an '#error' directive here is better than letting a downstream
    runtime assertion in 'round_to.hpp' fail as it inescapably would.
---
 currency.hpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/currency.hpp b/currency.hpp
index 4321525..fa83e7a 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -32,8 +32,14 @@
 #include <iostream>                     // ostream
 #include <vector>
 
+#define CURRENCY_UNIT_IS_CENTS
+
 #define CURRENCY_HAS_INTEGER_DATATYPE
 
+#if !defined CURRENCY_UNIT_IS_CENTS && defined CURRENCY_HAS_INTEGER_DATATYPE
+#   error No can do!
+#endif // !defined CURRENCY_UNIT_IS_CENTS && defined 
CURRENCY_HAS_INTEGER_DATATYPE
+
 #if !defined CURRENCY_HAS_INTEGER_DATATYPE
 #   if defined __GNUC__
 #       pragma GCC diagnostic push
@@ -54,8 +60,13 @@ class currency
     using data_type = double;
 #endif // !defined CURRENCY_HAS_INTEGER_DATATYPE
 
+#if defined CURRENCY_UNIT_IS_CENTS
     static constexpr int cents_digits = 2;
     static constexpr int cents_per_dollar = 100; // 10 ^ cents_digits
+#else  // !defined CURRENCY_UNIT_IS_CENTS
+    static constexpr int cents_digits = 0;
+    static constexpr int cents_per_dollar = 1; // 10 ^ cents_digits
+#endif // !defined CURRENCY_UNIT_IS_CENTS
 
     currency() = default;
     currency(currency const&) = default;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]