diff options
author | John Wiegley <johnw@newartisans.com> | 2003-09-30 03:43:04 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2003-09-30 03:43:04 +0000 |
commit | 52ed6fa013bc7cb4d377ab308a6b87536efb1e96 (patch) | |
tree | 9821171796ef9e6e73de61988dec97e12c8fd3d5 /amount.cc | |
parent | ef6161fefb09253b9de6d228c92ce41b3a0063dc (diff) | |
download | fork-ledger-52ed6fa013bc7cb4d377ab308a6b87536efb1e96.tar.gz fork-ledger-52ed6fa013bc7cb4d377ab308a6b87536efb1e96.tar.bz2 fork-ledger-52ed6fa013bc7cb4d377ab308a6b87536efb1e96.zip |
*** empty log message ***
Diffstat (limited to 'amount.cc')
-rw-r--r-- | amount.cc | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -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) |