1 diff --git a/src/ipelib/ipebase.cpp b/src/ipelib/ipebase.cpp
2 index 63de035..19226ad 100644
3 --- a/src/ipelib/ipebase.cpp
4 +++ b/src/ipelib/ipebase.cpp
5 @@ -557,55 +557,50 @@ Stream &Stream::operator<<(int i)
7 Stream &Stream::operator<<(double d)
13 + // Maximum number of digits in total
14 + const unsigned maxdigits=14;
16 + const unsigned bufsize=511;
17 + char buf[bufsize+1];
19 + // The number of digits left of '.'
20 + int intpartsize = 0;
23 + snprintf(buf, bufsize, "%.0f", fabs(d));
24 + intpartsize = strlen(buf);
27 - // PDF will not be able to read this, but we have to write something.
28 - // Such large numbers should only happen if something is wrong.
29 - std::sprintf(buf, "%g", d);
31 - } else if (d < 1e-8) {
34 - // Print six significant digits, but omit trailing zeros.
35 - // Probably I'll want to have adjustable precision later.
50 - factor = 100000000L;
51 - double dd = trunc(d);
52 - int intpart = int(dd + 0.5);
54 - int v = int(factor * (d - dd) + 0.5);
59 - std::sprintf(buf, "%d", intpart);
61 - int mask = factor / 10;
65 - putChar('0' + v / mask);
66 - v = (10 * v) % factor;
69 + // The nubmer of digits right of '.'
70 + int respartsize = maxdigits-intpartsize;
71 + if( respartsize < 0 )
74 + // Building the format string and get the string conversion of d
76 + snprintf(fmt, 255, "%%%d.%df", intpartsize, respartsize);
77 + snprintf(buf, bufsize, fmt, d);
80 + // Truncate redundant zeros and '.' from the right
81 + for(int i = strlen(buf)-1; i>=intpartsize; i--)
83 + // Truncate all zeros from right-hand
90 + // Remove decimal dot without decimal digits