Too many commas in gcalctool

Bug #208260 reported by Chris Sherlock
68
Affects Status Importance Assigned to Milestone
GCalctool
Fix Released
Critical
gcalctool (Ubuntu)
Fix Released
Low
Ubuntu Desktop Bugs
Nominated for Hardy by Ananth P

Bug Description

Binary package hint: gcalctool

If you subtract two numbers to get a number < 1,000 then the comma separator is doubled.

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

OK, now try typing in type in

1+(5+6)

This shows as:

 1,+(5,+6)

So I believe that there is something very wrong going on here.

This is happening on: Ubuntu hardy (development branch), release: 8.04

gcalctool version is 5.22.x

I have logged bug number 524746 with Gnome, but logging a parallel bug report here.

Revision history for this message
toobuntu (toobuntu) wrote :

Confirmed. I have been experiencing the same issues in Hardy.

Changed in gcalctool:
status: New → Confirmed
Revision history for this message
Pedro Villavicencio (pedro) wrote :

thanks for send it upstream.

Changed in gcalctool:
assignee: nobody → desktop-bugs
importance: Undecided → Low
status: Confirmed → Triaged
Revision history for this message
Chris Sherlock (ta-bu-shi-da-yu) wrote :

No probs :-)

Not sure if it's worthwhile saying so here, but 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 regardless...

Not sure how you'd get around this, but I think that's the problem here.

Revision history for this message
Morten Kjeldgaard (mok0) wrote :

This seems to be a reincarnation of bug #198250

Revision history for this message
Chris Sherlock (ta-bu-shi-da-yu) wrote :

Looks like a different issue to me... that issue seems to be a problem with the decimal point, this one is a problem with the whole expression being localised and adding in commas every third character.

Haven't seen the diff where they fixed it though, so YMMV.

Revision history for this message
Ananth P (ananthp) wrote :

I noticed that when the displayed number is result of a calculation, the thousand separator gives wrong set of commas. But if we clear the screen, and type in (or paste) the same number, the commas are correct.

E.g.
 - Paste 16666666669 --> 16,666,666,669
 - 16666666669 * 1 --> 16,,66,6,6,66,,669

Hope this helps to narrow down the problem.

Revision history for this message
Ananth P (ananthp) wrote :

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.

Revision history for this message
Ananth P (ananthp) wrote :

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.

Revision history for this message
Chris Sherlock (ta-bu-shi-da-yu) wrote :

Does that work for numbers with a decimal place?

Revision history for this message
Chris Sherlock (ta-bu-shi-da-yu) wrote :

I believe the main gcalctool dev has taken on board my feedback and implemented a localize_expression function.

Revision history for this message
Ananth P (ananthp) wrote :

Chris,

 - Yes. It works for numbers with decimal point.
 - As you said, I see that the duplicate item under gnome-bugs #524746 is fixed around the same time I submitted the patch, as a part of all other 'thousand separator' problem. So I think this patch would not be necessary.

Changed in gcalctool:
status: Unknown → Invalid
Changed in gcalctool:
status: Invalid → Confirmed
Revision history for this message
gdi2k (gdi2k) wrote :

It sounds like this might have already been fixed in the new version of gcalctool:
http://bobthegnome.blogspot.com/2008/04/gcalctool-5231.html

From the page:
* Fixes issues with thousands seperators and radix in non-english
locales (Bug #527669)

Revision history for this message
camel9 (jp-gonzalezguzman) wrote :

How do I apply this patch? Should I compile the file or what? Full instructions would be appreciated!

Revision history for this message
Ananth P (ananthp) wrote :

camel9,

This was my first patch here. So please don't take my word as authoritative information. Meaning that this may not be the best way to do it. Just one way. :-)

As pointed out by gdi2k, this problem had already been fixed by some other patch, which also fixes additional issues, just before I submitted the patch for this specific problem. But the fix is yet to be available in ubuntu repositories. So simple way to get the update for now, would be to download latest gcalctool from gnome website and install.

But if you just want to know how source patching works, try this:

1. Download the source code with the following command. This will get you version 5.22.1 as per this writing: "sudo apt-get source gcalctool"
2. Extract source code from the tar archive to some folder e.g. /tmp
3. Download the patch file and use the patch command to apply the patch to your source code e.g.: patch --input=/tmp/thousand_separator_fix_raguanu.patch
4. When asked provide path to display.c and the file will be patched/updated. e.g. /tmp/gcalctool-5.22.1/gcalctool/display.c
5. After this is done you need to compile the source code. I suggest you to use IDEs (Anjuta) which will make the process easy.

I realized that I didn't prepare the patch file well in order to facilitate easy applying. I will take this note next time.

Hope this helps,
Ragu

Changed in gcalctool:
status: Triaged → Fix Committed
Changed in gcalctool:
status: Confirmed → Fix Released
Revision history for this message
Pedro Villavicencio (pedro) wrote :

this should be fixed with the proposed packages on bug 44756

Changed in gcalctool:
status: Fix Committed → Fix Released
Changed in gcalctool:
importance: Unknown → Critical
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.