[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 37b663fe 11/27: Add an option to format cents
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 37b663fe 11/27: Add an option to format cents as decimal dollars |
Date: |
Mon, 25 Apr 2022 12:56:15 -0400 (EDT) |
branch: master
commit 37b663feddc0988686962f2894eb1298a84f551e
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add an option to format cents as decimal dollars
---
ledger_test.cpp | 2 ++
ledger_text_formats.cpp | 9 ++++++---
oecumenic_enumerations.hpp | 1 +
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/ledger_test.cpp b/ledger_test.cpp
index d2c1df95..57908211 100644
--- a/ledger_test.cpp
+++ b/ledger_test.cpp
@@ -88,12 +88,14 @@ void ledger_test::test_ledger_format()
constexpr std::pair<int,oenum_format_style> f4(2, oe_format_percentage);
constexpr std::pair<int,oenum_format_style> g1(9, oe_format_normal);
constexpr std::pair<int,oenum_format_style> g2(4, oe_format_percentage);
+ constexpr std::pair<int,oenum_format_style> g3(4, oe_cents_as_dollars);
LMI_TEST_EQUAL("3" , ledger_format(pi, f1));
LMI_TEST_EQUAL("3.14" , ledger_format(pi, f2));
LMI_TEST_EQUAL("314%" , ledger_format(pi, f3));
LMI_TEST_EQUAL("314.16%" , ledger_format(pi, f4));
LMI_TEST_EQUAL("3.141592654", ledger_format(pi, g1));
LMI_TEST_EQUAL("314.1593%" , ledger_format(pi, g2));
+ LMI_TEST_EQUAL("0.0314" , ledger_format(pi, g3));
}
void ledger_test::test_speed()
diff --git a/ledger_text_formats.cpp b/ledger_text_formats.cpp
index 85a96e05..47bf3fe7 100644
--- a/ledger_text_formats.cpp
+++ b/ledger_text_formats.cpp
@@ -1191,10 +1191,13 @@ std::string ledger_format
interpreter.precision(f.first);
std::string s;
- if(f.second)
+ switch(f.second)
{
- d *= 100;
+ case oe_format_normal: {} break; // Deliberately do nothing.
+ case oe_cents_as_dollars: {d /= 100;} break;
+ case oe_format_percentage: {d *= 100;} break;
}
+
interpreter << d;
interpreter >> s;
if(!interpreter.eof())
@@ -1202,7 +1205,7 @@ std::string ledger_format
alarum() << "Formatting error." << LMI_FLUSH;
}
- if(f.second)
+ if(oe_format_percentage == f.second)
{
s += '%';
}
diff --git a/oecumenic_enumerations.hpp b/oecumenic_enumerations.hpp
index 15754289..61b5ddac 100644
--- a/oecumenic_enumerations.hpp
+++ b/oecumenic_enumerations.hpp
@@ -83,6 +83,7 @@ enum oenum_elasticity
enum oenum_format_style
{oe_format_normal
+ ,oe_cents_as_dollars
,oe_format_percentage
};
- [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, 2022/04/25
- [lmi-commits] [lmi] master 37b663fe 11/27: Add an option to format cents as decimal dollars,
Greg Chicares <=
- [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, 2022/04/25