After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 524746 - [ARITH] Too many commas in output
[ARITH] Too many commas in output
Status: RESOLVED DUPLICATE of bug 527669
Product: gnome-calculator
Classification: Core
Component: general
5.22.x
Other All
: Normal normal
: ---
Assigned To: gcalctool maintainers
gcalctool maintainers
Depends on:
Blocks:
 
 
Reported: 2008-03-28 05:42 UTC by Chris Sherlock
Modified: 2008-04-12 08:08 UTC
See Also:
GNOME target: ---
GNOME version: 2.21/2.22


Attachments
patch to fix the thousand separator problem (1.00 KB, patch)
2008-04-12 06:18 UTC, raguanu
none Details | Review

Description Chris Sherlock 2008-03-28 05:42:11 UTC
Please describe the problem:
If you subtract two numbers to get a number < 1,000 then the comma seperator is doubled. 

Steps to reproduce:
1. Type in 1000 - 2005
2. Press equals button
3. Result is -1,,005


Actual results:
Too many commas!

Expected results:
Only one comma to seperate the thousands. 

Does this happen every time?
Happens every time. 

Other information:
Comment 1 Chris Sherlock 2008-03-28 14:19:18 UTC
Also: try typing in type in

1+(5+6)

This shows as:

1,+(5,+6)
Comment 2 Rich Burridge 2008-03-28 15:17:04 UTC
Initial problem confirmed for arithmetic operator precedence mode.
Works find in left-to-right precedence mode.
Adjusting summary accordingly.

> Also: try typing in type in
> 1+(5+6)
> This shows as:
> 1,+(5,+6)

I'm not seeing this problem (in either AOP or LTR modes)
for the English locale I'm running in.
Comment 3 Chris Sherlock 2008-03-29 01:32:33 UTC
What is the English locale you are running in?
Comment 4 Chris Sherlock 2008-03-29 01:44:23 UTC
chris@ubuntu:~$ locale
LANG=en_AU.UTF-8
LC_CTYPE="en_AU.UTF-8"
LC_NUMERIC="en_AU.UTF-8"
LC_TIME="en_AU.UTF-8"
LC_COLLATE="en_AU.UTF-8"
LC_MONETARY="en_AU.UTF-8"
LC_MESSAGES="en_AU.UTF-8"
LC_PAPER="en_AU.UTF-8"
LC_NAME="en_AU.UTF-8"
LC_ADDRESS="en_AU.UTF-8"
LC_TELEPHONE="en_AU.UTF-8"
LC_MEASUREMENT="en_AU.UTF-8"
LC_IDENTIFICATION="en_AU.UTF-8"
LC_ALL=
Comment 5 Rich Burridge 2008-03-29 03:41:50 UTC
Here's mine:

$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
$
Comment 6 Chris Sherlock 2008-03-29 13:15:20 UTC
I suspect that the problem with gcalctool is because refresh_display() calls ui_set_display(). However, ui_set_display calls:

        if (v->noparens == 0) {
            localize_number(localized, str);
            str = localized;
        }

Basically, it looks like it's trying to localize the whole expression, but this function is only build to localize an individual *number*. Thus is adds in the comma every 3rd character regardles... 

Not sure how you'd get around this, but I think that's the problem here. 
Comment 7 Chris Sherlock 2008-03-29 13:28:13 UTC
P.S. sorry in advance if I'm on the wrong track. I ran gcalctool through a debugger and that's what I saw happening. 
Comment 8 Rich Burridge 2008-03-29 14:05:55 UTC
Any and all help is appreciated Chris. Thanks!
Comment 9 Chris Sherlock 2008-03-29 14:15:45 UTC
No probs. 

If I'm on the right track, I've two thoughts on the matter. One way to deal with this would be to create a new function called localize_expression() that parses the expression for numbers and on each number calls localize_number(). 

Alternatively, the problem portion of the code seems to be run only when you type in a new number to the calculator, so basically just loop backwards in *str until you find the start of the string, copy this number into a new string and call localize_number() on this. Then whack the number back into *str. 
Comment 10 Chris Sherlock 2008-03-29 14:16:48 UTC
Sorry, it's late here. What I meant to say was:

"loop backwards in *str until you find the start of the *number*"
Comment 11 Sascha Herrmann 2008-03-31 22:38:04 UTC
Just more fun on this:

when I run the calculator with locale en_US.UTF-8 and type 0.001 and then click the 1/x button "1,/(0.001)" will be displayed, hitting "=" displays "1,,000". When I change my locale to "de_DE" (with this locale "," is the decimal separator, "." the thousand separator) and type "0,00" or "0.00" the displayed text gets converted to 0,,00.

Version: 5.22.0 from Debian testing.
Comment 12 raguanu 2008-04-12 06:18:15 UTC
Created attachment 109104 [details] [review]
patch to fix the thousand separator problem

the change is in gactool/display.c
Comment 13 raguanu 2008-04-12 06:20:34 UTC
I am not sure where to submit the patch as I found the bug through ubuntu launchpad, and there is one duplicate. I submitted to either.

---

The issue was with the localize_number() function. It assumed that the string to format does not contain ,+*,etc. So it gave incorrect result when the expression already includes thousand separators. Moreover, the logic was not working well when there were non-digit characters in the expression e.g. (,),+,%, etc.

Minor update to the localize_number() function in gcalctool/display.c, provided in the attached patch. Basically we want to identify 3 contiguous digits, and we need to add the separator only if the next char is a number. If a non-digit char occurs, I reset the digit counter.

I tested this patch in all calculator modes satisfactorily. Things like 3,333,333,336+36,985 are working now.

I would appreciate if someone reviews this to see if it is acceptable.
Comment 14 Robert Ancell 2008-04-12 08:08:17 UTC
I've merged all the thousands separator bugs into bug 527669 with a recent patch that appears to have fixed most of these problems. Thanks if you took the time to make a patch, I reviewed them but unfortunately none of them fixed all the problems simultaneously. Please test the patch and raise any issues in the new bug. Thank you.

*** This bug has been marked as a duplicate of 527669 ***