From 1e2b68b258a8821c2724be8af5a7f2e171fdaeba Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 22 Nov 1999 05:09:40 +0000 Subject: [PATCH] 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 --- src/engine/util.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/engine/util.c b/src/engine/util.c index 0965649dc6..0e0af78f99 100644 --- a/src/engine/util.c +++ b/src/engine/util.c @@ -190,6 +190,10 @@ PrtAmtComma (char * buf, double val, int prec) 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 */ tmp = val; while (tmp > 1000.0) { @@ -197,7 +201,7 @@ PrtAmtComma (char * buf, double val, int prec) 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--) { int j; @@ -220,10 +224,10 @@ PrtAmtComma (char * buf, double val, int prec) /* print two or three decimal places */ if (3 == prec) { - ival = 0.5 + 1000.0 * (val-amt); + ival = 1000.0 * (val-amt); buf += sprintf (buf, "%03d", ival); } else { - ival = 0.5 + 100.0 * (val-amt); + ival = 100.0 * (val-amt); buf += sprintf (buf, "%02d", ival); } @@ -237,6 +241,9 @@ xaccSPrintAmount (char * bufp, double val, short shrs) if (!bufp) return 0; + if (DEQ(val, 0.0)) + val = 0.0; + if (0.0 > val) { bufp[0] = '-'; bufp ++;