summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-24 15:13:21 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-24 15:13:21 -0400
commitf13709f71afec388f5dcc00f6fb468917390927d (patch)
treea1d5305fd6407b2257e3dfc4d38d71ac99431183 /src
parent1ecf62ce25e01def8a0df0a7c59047148c2cd734 (diff)
downloadledger-f13709f71afec388f5dcc00f6fb468917390927d.tar.gz
ledger-f13709f71afec388f5dcc00f6fb468917390927d.tar.bz2
ledger-f13709f71afec388f5dcc00f6fb468917390927d.zip
Be smarter about printing uncommoditized amounts
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 5d44251a..813cbac0 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -561,9 +561,11 @@ int amount_t::sign() const
}
namespace {
- void stream_out_mpq(std::ostream& out, mpq_t quant,
- amount_t::precision_t prec,
- const optional<commodity_t&>& comm = none)
+ void stream_out_mpq(std::ostream& out,
+ mpq_t quant,
+ amount_t::precision_t prec,
+ bool no_trailing_zeroes = false,
+ const optional<commodity_t&>& comm = none)
{
char * buf = NULL;
try {
@@ -584,6 +586,23 @@ namespace {
DEBUG("amount.convert",
"mpfr_print = " << buf << " (precision " << prec << ")");
+ if (no_trailing_zeroes) {
+ int index = std::strlen(buf);
+ int point = 0;
+ for (int i = 0; i < index; i++) {
+ if (buf[i] == '.') {
+ point = i;
+ break;
+ }
+ }
+ if (point > 0) {
+ while (--index >= point && buf[index] == '0')
+ buf[index] = '\0';
+ if (index >= point && buf[index] == '.')
+ buf[index] = '\0';
+ }
+ }
+
if (comm) {
int integer_digits = 0;
if (comm && comm->has_flags(COMMODITY_STYLE_THOUSANDS)) {
@@ -1006,7 +1025,7 @@ void amount_t::print(std::ostream& _out) const
out << " ";
}
- stream_out_mpq(out, MP(quantity), display_precision(), comm);
+ stream_out_mpq(out, MP(quantity), display_precision(), ! comm, comm);
if (comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))