Bug 159168 - kcalc showing multiple commas in floating point operations
Summary: kcalc showing multiple commas in floating point operations
Status: RESOLVED FIXED
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Klaus Niederkrüger
URL:
Keywords:
: 154475 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-11 23:54 UTC by David
Modified: 2008-06-11 22:17 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
screenshot (7.86 KB, image/jpeg)
2008-05-30 09:41 UTC, FiNeX
Details
schema of the problem (42.73 KB, application/pdf)
2008-05-31 10:39 UTC, FiNeX
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David 2008-03-11 23:54:55 UTC
Version:           svn (using Devel)
Installed from:    Compiled sources
OS:                Linux

This is a malfunction in kcalc program which will show multiple commas in floating point arithmetic, which sounds really studpid, despite the operation appears to be done correctly.

For example: do in kcalc 409 / 3, you will have: 1,36,,333,333,333
If you select edit -> copy the result of previous operation, you will get: 136,3333333333333333 in clipboard, which is the correct result, so this bug is probably related to display and not float handling.

Another example: 75/6 = 1,2,5
10000/60 = 1,66,666,666,667

I found out that in floating point operations, kmail always shows a comma after the first digit, which is definitely not correct.
Comment 1 David 2008-03-12 03:49:52 UTC
Sorry in last phrase, I meant kcalc (I was thinking in another bug of kmail so I mispelled the word :) )
Comment 2 FiNeX 2008-03-12 16:35:48 UTC
Confirmed with the "group digits" option selected.
Comment 3 Luiz 2008-05-01 20:59:05 UTC
I confirm this bug. It seems the bug is related to regional & language settings. Changing decimal symbols to "," and thousands separator do "," seems to solve it. With this, 10000/6=1666,666666666666667

Maybe it could be related to locales configuration against language & number settings. 
Comment 4 Luiz 2008-05-01 21:01:21 UTC
Correcting: changing decimal symbols to "," and thousands separator to "."
Comment 5 Luiz 2008-05-01 21:07:20 UTC
One more comment: I'm using the package kcalk-kde4 4.0.3-0ubuntu4 in kubuntu 8.04 (kcalc version 2.2 in kde 4.0.3).
Comment 6 David Johnson 2008-05-03 09:33:14 UTC
SVN commit 803511 by brandybuck:

BUG: 159168
Fix text display


 M  +19 -27    kcalcdisplay.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=803511
Comment 7 FiNeX 2008-05-05 10:28:48 UTC
I've just compiled the revision 804150. I've deleted the ~/.kde4 directory.

I reproduced the bug.

75/6 = 1,2,5

After I've checked off the "group digits" option:

75/6 = 12,5


With the "group digits" option enabled I've got "1,2,5", with "group digits" disabled the result is "12,5".

After this test I've gone to the systemsettings for check the "country/region & language" config. There I've found the default settings:
Contry or region: not set (generic english)
decimal symbol: .
thousands separator: ,

I've changed to my country (Italy):
decimal symbol: ,
thousands separator: .

Now kcalc is correct:
with any settings of "group digits".
Comment 8 Luciano Leveroni 2008-05-18 19:54:30 UTC
I'm using current SVN (from a few days ago to be precise) and this annoying bug is still there, at least please turn off group digit by default for 4.1. Otherwise, this bug turns kcalc pretty much useless.

Thanks for your time.

Comment 9 David Johnson 2008-05-30 02:48:55 UTC
I am unable to reproduce this. Perhaps I do not know how, because I am a monolinguist. Do I need to install kde-i18n packages?

I go into "kcmshell language", and select region to be Italy. Under Numbers, the decimal symbol is ',' and the thousands separator is '.'. The example number shown below is "1.234.567,89". Then I start kcalc. I enter 7 5 / 6, and the result is 12,5. The same is true with or without "Group Digits" set.

I can certainly turn off "Group Digits" by default if people want. But it is hard to fix the underlying bug when I cannot reproduce it. Please help.
Comment 10 FiNeX 2008-05-30 09:41:37 UTC
Created attachment 25004 [details]
screenshot 

Just reproduce on trunk compiled yesterday
7/5/6 = result with double comma.
Comment 11 FiNeX 2008-05-30 09:56:24 UTC
I'm looking at the code... the problem seems be located on formatNumber(). Now I'm trying to find out the issue.
Comment 12 FiNeX 2008-05-30 12:00:57 UTC
Probably I've found the problem.
My locales setting is on it_IT which use "." as thousand separator and "," as decimal symbol.
KDE default setting use "," as thousand separator and "." as decimal symbol.

When kget calc a result, the main function use the system locales setting, not the KDE one.

When _insertSeparator() is called it look for the "decimalSymbol" which in this case is "." but the "str" is already localized with the ",".

_insertSeparator() need as input a valid string which contains the right decimal symbol.

I've tried to regenerate my locales to en_US, in this way kcalc is correct (with KDE localization on en_US). If I set my locales to it_IT and KDE too, all is correct too. When system locale setting and KDE locale setting are different you can reproduce the bug.
Comment 13 David Johnson 2008-05-31 06:19:42 UTC
I do not know what you mean when you say "When kget calc a result". KCalc is using KGlobal::locale()->formatNumber() to format its numbers. Are you suggesting that kcalc not use KLocale::formatNumber()? Why would you want that? Isn't this a bug in KLocale? Should I hack something up with QLocale instead?

I fail to understand how this is a kcalc bug.
Comment 14 FiNeX 2008-05-31 10:39:08 UTC
"When kget calc a result": For example if your operation is: 75/6, the problem starts on knumber_priv.cpp on the divide() function which return "12,5" instead of "12.5".

After this, _insertSeparator() look for the decimal separator ("."), it is not found, and the thousand separator is inserted between "1" and "2". This cause the strange result "1,2,5" reported from me, and other people.

You need to know how the numbers calculated on knumber_priv.cpp are formatted, otherwise you will get errors.

formatNumber() (klocale.cpp:1111) assume that the number use "." as decimal separator, probably because it is assumed that the number to convert is not already well formatted.

I don't know the best way to solve this problem. Probably kcalc should check the system wide settings and manage calculation accordingly.
Comment 15 FiNeX 2008-05-31 10:39:35 UTC
Created attachment 25024 [details]
schema of the problem
Comment 16 David Johnson 2008-05-31 19:57:53 UTC
SVN commit 814914 by brandybuck:

BUG: 159168
Thanks for the explanation. It enabled me to finally reproduce the bug. gmplib is using system locale. Solution is to force LC_NUMERIC to "C" with setlocale. I have tested this with a variety of system and KDE locales.


 M  +4 -0      kcalc.cpp  
 M  +1 -0      kcalcdisplay.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=814914
Comment 17 FiNeX 2008-06-03 09:18:39 UTC
Great! The patch is perfect. Thanks a lot David!!!
Comment 18 David Johnson 2008-06-11 22:17:40 UTC
*** Bug 154475 has been marked as a duplicate of this bug. ***