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 566929 - Wrong result for decimal point calculations in german locale
Wrong result for decimal point calculations in german locale
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
5.25.x
Other All
: Normal major
: 2.26.0
Assigned To: gcalctool maintainers
gcalctool maintainers
: 568191 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-01-07 17:56 UTC by Sebastian Keller
Modified: 2009-02-09 23:28 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26


Attachments
use v->radix instead of "." (805 bytes, patch)
2009-01-19 01:52 UTC, Sebastian Keller
none Details | Review

Description Sebastian Keller 2009-01-07 17:56:16 UTC
Please describe the problem:
When using the german locale the results from multiplications with numbers with more than one digits after the comma are wrong.

Steps to reproduce:
LANG=de_DE.utf8 gcalctool
90*0,25 = 225 <- FAIL
90*2,5 = 225
90*0,2 = 18
90*0,3 = 27

LANG=C gcalctool
90*0.25 = 22.5 <- Correct

Actual results:
A small mathematical inaccuracy ;)

Expected results:
The correct result

Does this happen every time?
yes

Other information:
Comment 1 Robert Ancell 2009-01-12 09:59:39 UTC
I've tried this with the head version and the 5.24 branch and am unable to reproduce. Can you confirm this is still occurring? What keys are you using to enter the equations? Thanks.
Comment 2 Sebastian Keller 2009-01-12 12:11:34 UTC
5.25.4-0ubuntu1
It does not matter whether I use , or . - both results in , in the german locale; for both the result is wrong. This also happens if I use the , button of gcalctool.
Comment 3 Sebastian Keller 2009-01-19 00:38:17 UTC
Seems like it is a problem with displaying the results:
90*0,25 = 225
*10 = 225
*10 = 2250

90*0,025 = 225
*10 = 225
*10 = 225
*10 = 2250
Comment 4 Sebastian Keller 2009-01-19 01:36:43 UTC
The problem is in mp_cast_to_string. In line 545 it uses a "." instead of v->radix. So the created string for "1,2" would be "1.2". "." however in the german locale is v->tsep so it gets cleaned in localize_expression which results in "12" being displayed.
mp_cast_to_string gets called from display_refresh.
Comment 5 Sebastian Keller 2009-01-19 01:52:03 UTC
Created attachment 126730 [details] [review]
use v->radix instead of "."

This fixes the issue for me and does not seem to introduce any regression in the C locale.
It does not check if it writes over target_len, but neither did the old solution or any other part of that function.
Comment 6 Robert Ancell 2009-01-19 02:19:42 UTC
Thanks Sebastian!
Comment 7 Robert Ancell 2009-01-21 21:58:25 UTC
*** Bug 568191 has been marked as a duplicate of this bug. ***
Comment 8 Thomas Andersen 2009-02-05 13:20:29 UTC
Still seeing this in 2.25.90 with en_DK.UTF-8
Comment 9 Robert Ancell 2009-02-05 23:27:59 UTC
Sorry, this was missed for 2.25.90, it will be in 2.25.91
Comment 10 Robert Ancell 2009-02-08 12:09:16 UTC
Fixed for 2.25.91:
http://svn.gnome.org/viewvc/gcalctool?view=revision&revision=2363

The fix is a bit different - the internal representation should use '.' for the decimal point. It now correctly converts this to a ',' only when displaying in de_DE.UTF-8
Comment 11 Thomas Andersen 2009-02-09 15:56:54 UTC
I'm slightly confused by comment #10. I tested with da_DK and it is fixed there as well. So the fix is not de_DE only?

Either way it works for me now, so I'm happy :)
Comment 12 Robert Ancell 2009-02-09 23:28:28 UTC
Yeah, that commet was a bit rushed :) Correction: It should be fixed for all locales that do not use '.' as the radix.