[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.
- [lmi-commits] [lmi] master updated (c50cc9b1 -> 09e00258), Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 8ea7412a 01/27: Allow "touchstone" files to contain '\t', Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 20297761 05/27: Add a new ledger emission option, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master d4083917 07/27: Test eleven farraginous files nychthemerally, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master d195c7af 10/27: Add a unit test for ledger_format(), Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 3064fee4 09/27: Add a helper function with a deliberately ugly name,
Greg Chicares <=
- [lmi-commits] [lmi] master 37b663fe 11/27: Add an option to format cents as decimal dollars, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 550db6d9 15/27: Record speed measurements, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master a7d075cd 16/27: Document, suppress, or expunge unused formats, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master fdb47029 08/27: Fix dblize()ation in commented-out code, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 174198af 12/27: Reformat, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master dcbe9418 14/27: Change currency fields in ledger to integral cents, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master af0666c3 24/27: Distinguish two ledger formats, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 7b30e2d8 03/27: Filter unexpectedly small system-test discrepancies, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master d7ab80c6 04/27: Clean up beforehand, not afterward, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 12192723 06/27: Add two new ledger emission options, Greg Chicares, 2022/04/25