From 52ed6fa013bc7cb4d377ab308a6b87536efb1e96 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 30 Sep 2003 03:43:04 +0000 Subject: *** empty log message *** --- amount.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'amount.cc') diff --git a/amount.cc b/amount.cc index b3ce8b2e..b222e865 100644 --- a/amount.cc +++ b/amount.cc @@ -296,13 +296,27 @@ static std::string amount_to_str(const commodity * comm, const mpz_t val, else s << '.'; - if (full_precision) - s.width(MAX_PRECISION); - else + if (mpz_sgn(rquotient) == 0) { s.width(comm->precision); + s.fill('0'); + s << 0; + } else { + char buf[MAX_PRECISION + 1]; + gmp_sprintf(buf, "%Zd", rquotient); + + int width = std::strlen(buf); + char * p = buf + (width - 1); - s.fill('0'); - s << rquotient; + width = MAX_PRECISION - width; + + while (p >= buf && *p == '0') + p--; + *(p + 1) = '\0'; + + s.width(width + std::strlen(buf)); + s.fill('0'); + s << buf; + } if (! comm->prefix) { if (comm->separate) -- cgit v1.2.3