Bug 56669

Summary: KCalc should have digit grouping
Product: [Applications] kcalc Reporter: Antiphon <antiphon99>
Component: generalAssignee: Klaus Niederkrüger <kniederk>
Status: RESOLVED FIXED    
Severity: normal CC: gregor.rakar, kkk, mbertier, nicolasg, sergey_feo, sibskull, skyhusker
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: digits grouping in binary, decimal and hexadecimal mode.

Description Antiphon 2003-03-31 16:01:18 UTC
Version:           1.3.2 (using KDE 3.1.1)
Installed from:     (3.0)
Compiler:          gcc version 2.95.4 20011002 (Debian prerelease)
OS:          Linux (i686) release 2.4.20

KCalc does not follow the regional settings for how numbers should be displayed. If I have set my thousands separator to "." KCalc should use it when displaying numbers such as 7.000 instead of 7000.

It's easier to read and more in keeping with the KDE consistency.
Comment 1 Thiago Macieira 2003-07-21 23:47:21 UTC
*** Bug 59240 has been marked as a duplicate of this bug. ***
Comment 2 Klaus Niederkrüger 2004-03-31 11:30:27 UTC
*** Bug 76340 has been marked as a duplicate of this bug. ***
Comment 3 Klaus Niederkrüger 2004-03-31 11:31:50 UTC
*** Bug 76894 has been marked as a duplicate of this bug. ***
Comment 4 Nicolas Goutte 2004-08-20 22:27:02 UTC
I think that it is a bug, as KCalc does not use at all the locale settings, for example for the decimal symbol.

Have a nice day!
Comment 5 Nicolas Goutte 2004-08-20 22:27:49 UTC
*** Bug 79599 has been marked as a duplicate of this bug. ***
Comment 6 Alberto García Hierro 2004-08-22 18:27:12 UTC
At this time, KCalc uses '.' as decimal separator, so inserting thousand separator may cause inconsistences. I'm working on changing the decimal separator to the symbol specified in the locale preferences. This is the first step in order to fix this bug.
Comment 7 Alberto García Hierro 2004-08-22 23:13:41 UTC
CVS commit by hierro: 

Changed the decimal separator, know it honors the
global locale settings. First step for fixing bug #56669.
CCMAIL:56669@bugs.kde.org


  M +1 -1      kcalc.cpp   1.164
  M +41 -21    kcalcdisplay.cpp   1.17



Comment 8 Alberto García Hierro 2004-08-23 02:14:55 UTC
CVS commit by hierro: 

Changed decimal separator to the symbol specified in the locale
settings. Added thousands separators based on locale settings too.
Fixes bug #56669.
CCMAIL:56669-done@bugs.kde.org


  M +51 -3     kcalcdisplay.cpp   1.20
  M +1 -0      kcalcdisplay.h   1.11


--- kdeutils/kcalc/kcalcdisplay.cpp  #1.19:1.20
@@ -29,4 +29,5 @@
 #include <qclipboard.h>
 
+#include <kglobal.h>
 #include <klocale.h>
 #include <knotifyclient.h>
@@ -276,6 +277,53 @@ bool KCalcDisplay::setAmount(CALCAMNT ne
 void KCalcDisplay::setText(QString const &string)
 {
-        QLabel::setText(string);
-        emit changedText(string);
+        QString localizedString = string;
+        
+        // If we aren't in decimal mode, we don't need to modify the string
+        if (_num_base == NB_DECIMAL)
+        {
+                // Obtain decimal symbol and thousands separator
+                QString decimalSymbol = KGlobal::locale()->decimalSymbol();
+                QString thousandsSeparator = KGlobal::locale()->thousandsSeparator();
+        
+                // Replace dot with locale decimal separator
+                localizedString.replace(QChar('.'),decimalSymbol);
+        
+                // Insert the thousand separators
+                int i = localizedString.find(decimalSymbol) != -1? localizedString.find(decimalSymbol)-1: localizedString.length()-1;
+                for(int j=1;i>0;i--,j++)
+                        if (j%3 == 0)
+                                localizedString.insert(i,thousandsSeparator);
+        }
+
+        QLabel::setText(localizedString);
+        emit changedText(localizedString);
+}
+
+QString KCalcDisplay::text() const
+{
+        if (_num_base != NB_DECIMAL)
+                return QLabel::text();
+        
+        QString unlocalizedString = QLabel::text();
+        
+        // Obtain decimal symbol and thousands separator
+        QString decimalSymbol = KGlobal::locale()->decimalSymbol();
+        QString thousandsSeparator = KGlobal::locale()->thousandsSeparator();
+
+        // TODO: This may cause problems if the user
+        // sets decimalSymbol == thousandsSeparator
+        // Since text() is only used for prepending
+        // other text in NB_HEX mode and measuring
+        // the display lenght, this is not a big
+        // problem. Anyway, we should find a 
+        // better way of doing this.
+
+        // Delete thousands separators  
+        unlocalizedString.remove(thousandsSeparator);
+        
+        // Replace decimalSymbol with '.'
+        unlocalizedString.replace(decimalSymbol,QChar('.'));
+        
+        return unlocalizedString;
 }
 

--- kdeutils/kcalc/kcalcdisplay.h  #1.10:1.11
@@ -108,4 +108,5 @@ public:
         void setPrecision(int precision);
         void setText(QString const &string);
+        QString text() const;
         bool updateDisplay(void);
 private:


Comment 9 Roger 2004-08-23 04:17:21 UTC
I'm away from kde but this change looks to only consider decimal mode. I'd like for grouping to work with binary as well. Somewhat like this: "1011 0011 1111 1111"  etc ...  This is what I was hoping for actually :)  New wish?
Comment 10 Alberto García Hierro 2004-08-23 16:12:36 UTC
Roger: Please, file a bug report and assign it to me. I will take care as soon as possible.
Comment 11 Matej Pivoluska 2004-11-25 21:31:23 UTC
Created attachment 8437 [details]
digits grouping in binary, decimal and hexadecimal mode.
Comment 12 Andrew Rule 2005-02-26 14:25:16 UTC
Bug not resolved using kcalc 1.6 and KDE 3.3.2 on Debian (testing).  
The locale is used for the "keypad" part of the display, but not for the number you are working on - which tends to be where you look, anyway!  
The decimal point shows correctly on the "keypad" but not for the number displayed, and the thousands separator isn't used for the number displayed at all.

What version of Kcalc has the patch?  Or has it been released yet?
Comment 13 sergey 2008-10-08 21:17:03 UTC
[ ex
Bug seems not resolved using kcalc 2.0.6 under Slackware 12.1 with locale ru_RU.utf8.  
The locale is not used neither for the "keypad" part of the display, nor for the number. For example, I see now 31,557,600.0000000000 in place of 31 557 600,00000000000.
This can be also bug of Slackware 12.1: when I start kcalc and many other applications from terminal emulator, I see the next message: "Qt: Locales not supported on X server". But applications use language that corresponds to locale.
Comment 14 sergey 2008-10-23 21:41:35 UTC
The message "Qt: Locales not supported on X server" was because of my error: locale should not be "ru_RU.utf8", but "ru_RU.UTF-8". I set locale to this correct value and have no this warning now. But bug in kcalc still here.

I try also kcalc in Mandriva 2009.0 (kde4). It has this ignore-locale bug too.