[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: patch to fix bug #18083
From: Ariya Hidayat <ariya () tf ! itb ! ac ! id>
Date: 2002-08-19 16:31:19
[Download RAW message or body]
The following patch fix bug #18083 (kspread rounding error).
Problem: in most system (including mine), printf("%.2f",x) results in
"63.15" if x is 63.145 but "64.14" if x is 64.145. For the latter, it
should be "64.15" (I checked with MS Excel). So it's not KLocale's or
QString's fault. I don't know exactly what might cause this (broken libc?)
Solution: round the number before passing it to KLocale::formatNumber().
Hopefully it doesn't introduce noticable penalty.
OK to commit ?
(John: sorry if this duplicates your work/investigation).
["rounding.patch" (TEXT/PLAIN)]
Index: kspread_cell.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_cell.cc,v
retrieving revision 1.435
diff -u -3 -p -r1.435 kspread_cell.cc
--- kspread_cell.cc 2002/08/18 15:20:28 1.435
+++ kspread_cell.cc 2002/08/19 16:14:41
@@ -1186,6 +1186,13 @@ QString KSpreadCell::createFormat( doubl
QString localizedNumber= locale()->formatNumber( value, p );
int pos = 0;
+ // round the number, based on desired precision
+ double m[] = { 1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10 };
+ double mm = (p > 10) ? pow(10.0,p) : m[p];
+ bool neg = value < 0;
+ value = floor( fabs(value)*mm + 0.5 ) / mm;
+ if( neg ) value = -value;
+
switch( formatType() )
{
case Number:
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic