GNOME Bugzilla – Bug 566929
Wrong result for decimal point calculations in german locale
Last modified: 2009-02-09 23:28:28 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:
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.
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.
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
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.
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.
Thanks Sebastian!
*** Bug 568191 has been marked as a duplicate of this bug. ***
Still seeing this in 2.25.90 with en_DK.UTF-8
Sorry, this was missed for 2.25.90, it will be in 2.25.91
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
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 :)
Yeah, that commet was a bit rushed :) Correction: It should be fixed for all locales that do not use '.' as the radix.