bug fix for rounding suggested by Dave petticolas

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1959 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
1999-11-22 05:09:40 +00:00
parent 1bf5ded474
commit 1e2b68b258

View File

@@ -190,6 +190,10 @@ PrtAmtComma (char * buf, double val, int prec)
return 3; return 3;
} }
/* Round to 100'ths or 1000'nths now. Must do this before we start printing. */
if (2 == prec) val += 0.005;
if (3 == prec) val += 0.0005;
/* count number of commas */ /* count number of commas */
tmp = val; tmp = val;
while (tmp > 1000.0) { while (tmp > 1000.0) {
@@ -197,7 +201,7 @@ PrtAmtComma (char * buf, double val, int prec)
ncommas ++; ncommas ++;
} }
/* print digits in groups of three, seperated by commas */ /* print digits in groups of three, separated by commas */
for (i=ncommas; i>=0; i--) { for (i=ncommas; i>=0; i--) {
int j; int j;
@@ -220,10 +224,10 @@ PrtAmtComma (char * buf, double val, int prec)
/* print two or three decimal places */ /* print two or three decimal places */
if (3 == prec) { if (3 == prec) {
ival = 0.5 + 1000.0 * (val-amt); ival = 1000.0 * (val-amt);
buf += sprintf (buf, "%03d", ival); buf += sprintf (buf, "%03d", ival);
} else { } else {
ival = 0.5 + 100.0 * (val-amt); ival = 100.0 * (val-amt);
buf += sprintf (buf, "%02d", ival); buf += sprintf (buf, "%02d", ival);
} }
@@ -237,6 +241,9 @@ xaccSPrintAmount (char * bufp, double val, short shrs)
if (!bufp) return 0; if (!bufp) return 0;
if (DEQ(val, 0.0))
val = 0.0;
if (0.0 > val) { if (0.0 > val) {
bufp[0] = '-'; bufp[0] = '-';
bufp ++; bufp ++;