[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 119df7a9 13/27: Add a 'divisor' argument to L
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 119df7a9 13/27: Add a 'divisor' argument to LedgerBase::value_str() |
Date: |
Mon, 25 Apr 2022 12:56:15 -0400 (EDT) |
branch: master
commit 119df7a91ebee3ca605b1f9c1697e713156330bd
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add a 'divisor' argument to LedgerBase::value_str()
The motivation is to allow formatting integral cents as decimal dollars.
It's not worth making this any prettier, because it's used only in one
function; ideally only one routine (not this one) would be used for
formatting all ledger data.
---
ledger_base.cpp | 10 ++++++++--
ledger_base.hpp | 2 ++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/ledger_base.cpp b/ledger_base.cpp
index fb4c74f4..9f9d0b15 100644
--- a/ledger_base.cpp
+++ b/ledger_base.cpp
@@ -143,12 +143,15 @@ void LedgerBase::Copy(LedgerBase const& obj)
std::string LedgerBase::value_str
(std::string const& map_key
,int index
+ ,double divisor
) const
{
+ LMI_ASSERT(0.0 != divisor);
+
double_vector_map::const_iterator found = AllVectors.find(map_key);
if(AllVectors.end() != found)
{
- return value_cast<std::string>((*(*found).second)[index]);
+ return value_cast<std::string>((*(*found).second)[index] / divisor);
}
alarum() << "Map key '" << map_key << "' not found." << LMI_FLUSH;
@@ -158,8 +161,11 @@ std::string LedgerBase::value_str
//============================================================================
std::string LedgerBase::value_str
(std::string const& map_key
+ ,double divisor
) const
{
+ LMI_ASSERT(0.0 != divisor);
+
string_map::const_iterator found_string = Strings.find(map_key);
if(Strings.end() != found_string)
{
@@ -169,7 +175,7 @@ std::string LedgerBase::value_str
scalar_map::const_iterator found_scalar = AllScalars.find(map_key);
if(AllScalars.end() != found_scalar)
{
- return value_cast<std::string>(*(*found_scalar).second);
+ return value_cast<std::string>(*(*found_scalar).second / divisor);
}
alarum() << "Map key '" << map_key << "' not found." << LMI_FLUSH;
diff --git a/ledger_base.hpp b/ledger_base.hpp
index e930ff2a..0cbbef0a 100644
--- a/ledger_base.hpp
+++ b/ledger_base.hpp
@@ -182,9 +182,11 @@ class LMI_SO LedgerBase
std::string value_str
(std::string const& map_key
,int index
+ ,double divisor = 1.0
) const;
std::string value_str
(std::string const& map_key
+ ,double divisor = 1.0
) const;
double_vector_map const& all_vectors() const;
- [lmi-commits] [lmi] master 37b663fe 11/27: Add an option to format cents as decimal dollars, (continued)
- [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
- [lmi-commits] [lmi] master 119df7a9 13/27: Add a 'divisor' argument to LedgerBase::value_str(),
Greg Chicares <=
- [lmi-commits] [lmi] master 2b108ed7 18/27: Avoid unnecessary rounding, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master b7c61b4d 20/27: Regularize format names, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 8de190ce 17/27: Regularize whitespace, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 0b6a3b69 02/27: Avoid writing " \n", Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 95b4e917 19/27: Remove an unnecessary comment, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 61f6a237 21/27: Reorder format-style map, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 299cc249 22/27: Improve documentation, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 6f50ad93 23/27: Transpose a ledger format, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 00289fa7 25/27: Rearrange ledger formats, Greg Chicares, 2022/04/25
- [lmi-commits] [lmi] master 16898eb9 26/27: Use a more reasonable format for an unused field, Greg Chicares, 2022/04/25