summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-03-04 17:07:15 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 05:48:44 -0400
commit7b591dd27a53f60aed7d2f6fe81d2953aa49b1b2 (patch)
tree4c06874bccf19922d326a7bd4b2ebefcfa683648
parent5766befbb760ee3bfb1d8defc3dc94ee04a7c1aa (diff)
downloadfork-ledger-7b591dd27a53f60aed7d2f6fe81d2953aa49b1b2.tar.gz
fork-ledger-7b591dd27a53f60aed7d2f6fe81d2953aa49b1b2.tar.bz2
fork-ledger-7b591dd27a53f60aed7d2f6fe81d2953aa49b1b2.zip
*** no comment ***
-rw-r--r--amount.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/amount.cc b/amount.cc
index 1fe2ecdd..5de0264c 100644
--- a/amount.cc
+++ b/amount.cc
@@ -810,14 +810,28 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt)
}
if (precision) {
- out << ((comm.flags & COMMODITY_STYLE_EUROPEAN) ? ',' : '.');
-
- out.width(precision);
- out.fill('0');
+ out << ((comm.flags() & COMMODITY_STYLE_EUROPEAN) ? ',' : '.');
+ std::ostringstream final;
+ final.width(precision);
+ final.fill('0');
char * p = mpz_get_str(NULL, 10, rquotient);
- out << p;
+ final << p;
std::free(p);
+
+ const std::string& str(final.str());
+ int i, len = str.length();
+ const char * q = str.c_str();
+ for (i = len; i > 0; i--)
+ if (q[i - 1] != '0')
+ break;
+
+ if (i == len)
+ out << str;
+ else if (i < comm.precision())
+ out << std::string(str, 0, comm.precision());
+ else
+ out << std::string(str, 0, i);
}
if (comm.flags & COMMODITY_STYLE_SUFFIXED) {