lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 3064fee4 09/27: Add a helper function with a


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 3064fee4 09/27: Add a helper function with a deliberately ugly name
Date: Mon, 25 Apr 2022 12:56:15 -0400 (EDT)

branch: master
commit 3064fee41902cf07de4fd612b81b8b5aa904522a
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Add a helper function with a deliberately ugly name
    
    This is a handy replacement for dblize() when cents are wanted rather
    than dollars. Occurrences of either dblize() or centize() are suspect,
    and should perhaps be replaced eventually.
---
 currency.hpp      | 13 +++++++++++++
 currency_test.cpp |  4 ++++
 2 files changed, 17 insertions(+)

diff --git a/currency.hpp b/currency.hpp
index 449cb7aa..d0338185 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -130,6 +130,19 @@ inline currency from_cents(double cents)
     return currency(cents, raw_cents{});
     }
 
+inline double centize(currency z) {return z.cents();}
+
+inline std::vector<double> centize(std::vector<currency> const& z)
+{
+    std::vector<double> r;
+    r.reserve(z.size());
+    for(auto const& i : z)
+        {
+        r.emplace_back(i.cents());
+        }
+    return r;
+}
+
 inline double dblize(currency z) {return z.d();}
 
 inline std::vector<double> dblize(std::vector<currency> const& z)
diff --git a/currency_test.cpp b/currency_test.cpp
index 078b052e..5cd28cb9 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -383,6 +383,10 @@ void currency_test::test_quodlibet()
     currency b3 = b0 + b1;
     LMI_TEST_EQUAL(b2.cents(), b3.cents());
     LMI_TEST_EQUAL(b2, b3);
+
+    currency const c0(777, raw_cents{});
+    double d0 = centize(c0);
+    LMI_TEST_EQUAL(d0, c0.cents());
 }
 
 // CURRENCY !! Ideas for testing overflow or underflow.



reply via email to

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