[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/007 7b3debe3 07/10: Add a 'divisor' argument
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/007 7b3debe3 07/10: Add a 'divisor' argument to LedgerBase::value_str() |
Date: |
Tue, 19 Apr 2022 19:00:41 -0400 (EDT) |
branch: valyuta/007
commit 7b3debe3c778db1ba08f84c236c7909408b9e0be
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] valyuta/007 updated (4c404956 -> 0b887792), Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 18a91e63 01/10: Fix dblize()ation in commented-out code, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 efa7b7a8 02/10: Add a helper function with a deliberately ugly name, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 1aeae253 03/10: Add a unit test for ledger_format(), Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 c55ec8f6 04/10: Add an option to format cents as decimal dollars, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 6569915e 06/10: Reformat, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 0b887792 10/10: Change many more ledger fields to cents, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 7b3debe3 07/10: Add a 'divisor' argument to LedgerBase::value_str(),
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/007 7535505d 09/10: Change several more ledger fields to cents, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 1189d3ac 05/10: Change a ledger field to cents, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 2d26a146 08/10: Change several more ledger fields to cents, Greg Chicares, 2022/04/19