Issue 70236 - CDbl truncates values with locale setting passed by an environment variable
Summary: CDbl truncates values with locale setting passed by an environment variable
Status: ACCEPTED
Alias: None
Product: Calc
Classification: Application
Component: code (show other issues)
Version: OOo 2.0.3
Hardware: PC Linux, all
: P3 Trivial with 8 votes (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords: oooqa
Depends on:
Blocks:
 
Reported: 2006-10-09 14:23 UTC by dindy
Modified: 2017-05-20 11:00 UTC (History)
8 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: 4.1.3
Developer Difficulty: ---


Attachments
Locale settings form screenshot (33.84 KB, image/png)
2007-04-02 17:43 UTC, dindy
no flags Details
example of not working cDbl and cSng on a French system with USA OOo (12.38 KB, text/plain)
2009-07-04 15:14 UTC, fyva
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description dindy 2006-10-09 14:23:51 UTC
This is the same bug reported on issue #21413, where it is asked to submit 
another issue if reproduced. 

When a locale which uses the comma as the decimal separator is passed by an 
environment variable, with a command line like:

env LANG="it_IT@euro" ooffice

a Basic Macro like this:

MsgBox CStr(CDbl("1234,5678"))

gives "1234" instead of "1234,5678". CDbl truncates the decimal part. 

This happens only under Linux, on Windows it works as expected. If the locale 
is set using Tools->Options->Language Settings->Languages it works also under 
Linux. The bugs happens only when the locale is set using the environment.

I tested this only with Calc and Italian locale settings, but probably it 
happens also with other components and with other locales using the comma as 
the decimal separator.
Comment 1 olly600 2006-12-28 09:22:05 UTC
Please replicate the issue with OpenOffice version 2.1.

Thanks.
Comment 2 dindy 2007-01-04 13:36:08 UTC
I'll do as soon as I have OOo 2.1 installed on my Linux server. I'm waiting for 
the Fedora Core official update.
Comment 3 kpalagin 2007-03-23 01:55:38 UTC
Using 2.2RC3 on Suse 10.2
Depending on what I set Tools - Options - Language Settings - Languages - 
Localle Setting I see following behavior
1. Default (US English, "." as decimal separator) - I see "12345678" as output 
of "MsgBox CStr(CDbl("1234,5678"))"
2. Italian (Italy) ("," as decimal separator) - I get "1234,5678" as output of 
the macro.
3. Italian (Italy) ("," as decimal separator) - I get "55,359722222" as output 
of "MsgBox CStr(CDbl("1234.5678"))" (note dot as decimal separator).

dindy,
please specify how do I use enviroment variable to pass localle setting to OO 
macro.
Thanks.
Comment 4 dindy 2007-03-23 09:40:00 UTC
Hello Kpalagin,

I'm probably missing your question. In the first message I reported:

env LANG="it_IT@euro" ooffice

Isn't this enough? 

BTW, I haven't tested yet with 2.1, sorry. Fedora Core 5 is still at 2.0.2 and 
unfortunately I'm quite busy so I have little time to download a newer version 
from some other source and test with it, but if it's really needed I'll try to 
find some spare time and do the tests.

Thanks for your efforts.

Bye,
Comment 5 kpalagin 2007-03-23 14:45:42 UTC
Confirming with 2.2RC3 on Suse 10.2:
1. Starting OO with localle specified in command line produces "1234" as an 
output of MsgBox CStr(CDbl("1234,5678"))
2. Setting "Italy" in Tools->Options->Language Settings->Languages and running 
MsgBox CStr(CDbl("1234,5678")) produces "1234,5678".
Comment 6 frank 2007-03-27 15:31:34 UTC
Hi,

tried it with FC and could not reproduce. Tried again with Suse 10.1 and can
reproduce.

Andreas please have a look at this one. QA framework has a machine there I can
show you the problem.

Frank
Comment 7 ab 2007-03-28 09:49:04 UTC
ab->er: As already described in #i21413, I have no idea what can be
done in Basic to solve this problem. Basic can do nothing here but 
rely on the information provided by SvtSysLocale and under certain
circumstances this information seems to be not correct. As you are
the cvs owner of svtools/inc/syslocale.hxx I reassign this task to you.
Comment 8 ooo 2007-03-28 12:33:00 UTC
Dindy,

The LANG variable has a low precedence and may get overridden by the LC_ALL and
LC_CTYPE (which itself may be overridden by LC_ALL again) variables. Check with
the command 'locale' if these are set to a locale that has a different decimal
separator. "Set" here means that the actual environment variable is set, the
locale command in that case displays the value without quotes ("), as opposed to
a quoted value that designates an inherited value from the actual locale
selected. You may also check using the commands  echo $LC_ALL  respectively 
echo $LC_CTYPE  where any output means it will override your LANG value.

  Eike
Comment 9 dindy 2007-03-28 12:41:51 UTC
Hello Eike,

I'm not sure I completely understand your request. BTW the locale command by 
itself gives the following output:

[root@server ~]# locale
LANG=en_US
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=

Instead the locale command with the same env variable as OOo gives the 
following output:

[root@server ~]# env LANG="it_IT@euro" locale
LANG=it_IT@euro
LC_CTYPE="it_IT@euro"
LC_NUMERIC="it_IT@euro"
LC_TIME="it_IT@euro"
LC_COLLATE="it_IT@euro"
LC_MONETARY="it_IT@euro"
LC_MESSAGES="it_IT@euro"
LC_PAPER="it_IT@euro"
LC_NAME="it_IT@euro"
LC_ADDRESS="it_IT@euro"
LC_TELEPHONE="it_IT@euro"
LC_MEASUREMENT="it_IT@euro"
LC_IDENTIFICATION="it_IT@euro"
LC_ALL=

This means that the env command actually completely changes the locale 
settings, as expected, isn't it?

Let me know if you need further tests.

Bye,
Comment 10 dindy 2007-03-28 12:49:03 UTC
Hello again Eike,

I tried also as the non root user which noraly run OOo. Same result. I also 
remember that, before opening this bug, I also tried by setting each single 
locale variable to the right value, both using the env command and by setting 
it in the shell rc, but nothing changed.

[denis@server ~]$ locale
LANG=en_US
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=

[denis@server ~]$ env LANG="it_IT@euro" locale
LANG=it_IT@euro
LC_CTYPE="it_IT@euro"
LC_NUMERIC="it_IT@euro"
LC_TIME="it_IT@euro"
LC_COLLATE="it_IT@euro"
LC_MONETARY="it_IT@euro"
LC_MESSAGES="it_IT@euro"
LC_PAPER="it_IT@euro"
LC_NAME="it_IT@euro"
LC_ADDRESS="it_IT@euro"
LC_TELEPHONE="it_IT@euro"
LC_MEASUREMENT="it_IT@euro"
LC_IDENTIFICATION="it_IT@euro"
LC_ALL=

Bye,
Comment 11 ooo 2007-04-02 17:12:56 UTC
Hi Dindy,

> Instead the locale command with the same env variable as OOo gives the 
> following output:
> 
> [root@server ~]# env LANG="it_IT@euro" locale
> [... all it_IT@euro ...]
> 
> This means that the env command actually completely changes the locale 
> settings, as expected, isn't it?

Yes, looks good. However, I also get the behavior in OOo as desired.

> Let me know if you need further tests.

Just to make sure we dont miss anything : what is the value of Tools ->
Options -> Language Settings -> Languages -> Locale setting?

If using the   env LANG="it_IT@euro" ooffice   command, are you able to input
numbers with the expected separators in the Calc spreadsheet application? Are
they correctly recognized as numbers, or do they stay text? You can tell by 1.
number is right aligned, text is left aligned, and 2. =SUM(cell) gives the
value, and not 0.

Thanks
  Eike
Comment 12 dindy 2007-04-02 17:42:44 UTC
Hello Heike,

I have to start oocal with the following command:

env LANG="it_IT@euro" DISPLAY="pisolo:0" oocalc

because the server has no monitor attached. The XServer is XFree86 under 
Cygwin/Win2000 Italian. BTW think it makes no difference. 

The "Tools -> Options -> Language Settings -> Languages -> Locale setting" menu 
path is in Italian. It becomes "Strumenti -> Opzioni -> Impostazioni lingua -> 
Lingue -> Schema locale". The value in the listbox is "Standard". All other  
values looks correct for the italian settings. I'll add an attachment with a 
screenshot of the form.

The comma "," is properly accepted as a decimal separator within oocalc, 
numbers are recognized as numbers, and not text. The dot "." is instead 
recognized as a time separator. Everything looks correct.

Bye,
Comment 13 dindy 2007-04-02 17:43:41 UTC
Created attachment 44165 [details]
Locale settings form screenshot
Comment 14 ooo 2007-04-03 11:46:02 UTC
Hi Dindy,

> Hello Heike,

Don't try to change my gender ;-)

> I have to start oocal with the following command:
> 
> env LANG="it_IT@euro" DISPLAY="pisolo:0" oocalc
> 
> because the server has no monitor attached. The XServer is XFree86 under 
> Cygwin/Win2000 Italian. BTW think it makes no difference. 

It shouldn't, if the machine where OOo runs on supports the locale.

> The "Tools -> Options -> Language Settings -> Languages -> Locale setting" menu 
> path is in Italian. It becomes "Strumenti -> Opzioni -> Impostazioni lingua -> 
> Lingue -> Schema locale". The value in the listbox is "Standard". All other  
> values looks correct for the italian settings. I'll add an attachment with a 
> screenshot of the form.

Everything fine there.

> The comma "," is properly accepted as a decimal separator within oocalc, 
> numbers are recognized as numbers, and not text. The dot "." is instead 
> recognized as a time separator. Everything looks correct.

Which in fact also means that the proper locale is used by OOo. Just
that Basic doesn't get it.


@ab: Andreas, how do you obtain the locale settings for CDbl? Please
give me a pointer to the source code in Basic.


@fst: Frank, what did you mean with
> tried it with FC and could not reproduce. Tried again with Suse 10.1 and
> can reproduce.
Are you sure the Suse machine had an it_IT@euro locale installed? Did
Calc use the proper locale settings?


Thanks
  Eike
Comment 15 ab 2007-04-03 12:43:35 UTC
ab->er: ImpGetIntntlSep in basic/source/sbx/sbxscan.cxx
Comment 16 ooo 2007-04-03 14:30:12 UTC
Andreas,

I think I found the culprit. The ImpScan() function that is internally used to
scan values from strings tries to be smart by removing group separators,
changing the decimal separator to a dot and then call atof() on the string. That
doesn't work, as on some systems functions like atof and strtof/strtod are
localized.

Please use ::rtl::math::stringToDouble() from rtl/math.hxx instead, which may as
well replace the entire while-loop except the 'D' Basic specialty.

  Eike
Comment 17 ab 2007-04-18 15:04:51 UTC
Thanks, Eike

STARTED
Comment 18 ab 2008-01-25 14:19:03 UTC
-> 3.x
Comment 19 fyva 2009-07-04 11:52:51 UTC
cSng truncates the value too. It is for French, Russian locales too.
Sub Main
Separator = Left(Right(cStr(1.1), 2), 1)
msgbox cDbl("123"+Separator+"1234") ' Shows "123". Should show 123,1234 for
msgbox cSng("123"+Separator+"1234")
'French, Russian and similar locales where "," is a separator
End Sub

Comment 20 fyva 2009-07-04 12:33:14 UTC
Operating System is Linux. Spanish is affected too.
This issue is confirmed for
Linux:
3.0.1 for Russian and French
3.1.0 for Russian, French, Spanish
OOO310m14 for Russian

This issue does not appear on Windows with OOO310m11.
Comment 21 fyva 2009-07-04 13:26:00 UTC
In the above examples the word "locale" means the System locale+OOo locale. For
example, "French locale" means the system user interface is French and the OOo
user interface is French and all OOo language settings are French. For Russian
it means ALL is Russian. For Spanish, ALL is Spanish. If use USA system locale
plus USA build of OOo, but in the language settings for OOo to choose Russian
locale, then the separator is comma (","), but the issue does not apper and cDbl
with cSng work correct, showing 123,1234. It means, you can't test this issue
just by changing locale in OOo, you need to change ALL system locale variables,
that is easily done on Linux by creating new users and installing language packs
for OOo and the system.
Comment 22 fyva 2009-07-04 14:48:53 UTC
To test this issue on Linux it is sufficient to change the system locale. This
issue does not depend on OOo locale and even on the separator used by OOo.
Just these system variables are important:

LANG=ru_RU.UTF-8
LC_CTYPE="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_COLLATE="ru_RU.UTF-8"
LC_MONETARY="ru_RU.UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_PAPER="ru_RU.UTF-8"
LC_NAME="ru_RU.UTF-8"
LC_ADDRESS="ru_RU.UTF-8"
LC_TELEPHONE="ru_RU.UTF-8"
LC_MEASUREMENT="ru_RU.UTF-8"
LC_IDENTIFICATION="ru_RU.UTF-8"
LC_ALL=

LANG=es_ES.UTF-8
LC_CTYPE="es_ES.UTF-8"
LC_NUMERIC="es_ES.UTF-8"
LC_TIME="es_ES.UTF-8"
LC_COLLATE="es_ES.UTF-8"
LC_MONETARY="es_ES.UTF-8"
LC_MESSAGES="es_ES.UTF-8"
LC_PAPER="es_ES.UTF-8"
LC_NAME="es_ES.UTF-8"
LC_ADDRESS="es_ES.UTF-8"
LC_TELEPHONE="es_ES.UTF-8"
LC_MEASUREMENT="es_ES.UTF-8"
LC_IDENTIFICATION="es_ES.UTF-8"
LC_ALL=

LANG=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
 And other similar locales (Italian, etc) with internal comma separator (?)
Comment 23 fyva 2009-07-04 15:14:14 UTC
Created attachment 63361 [details]
example of not working cDbl and cSng on a French system with USA OOo
Comment 24 raal 2010-06-15 14:04:05 UTC
Same problem on ubuntu 9.10, DEV300m82, Czech locale,comma as the decimal separator.
LANG=cs_CZ.UTF-8
LANGUAGE=cs_CZ.UTF-8
LC_CTYPE="cs_CZ.UTF-8"
LC_NUMERIC="cs_CZ.UTF-8"
LC_TIME="cs_CZ.UTF-8"
LC_COLLATE="cs_CZ.UTF-8"
LC_MONETARY="cs_CZ.UTF-8"
LC_MESSAGES="cs_CZ.UTF-8"
LC_PAPER="cs_CZ.UTF-8"
LC_NAME="cs_CZ.UTF-8"
LC_ADDRESS="cs_CZ.UTF-8"
LC_TELEPHONE="cs_CZ.UTF-8"
LC_MEASUREMENT="cs_CZ.UTF-8"
LC_IDENTIFICATION="cs_CZ.UTF-8"
LC_ALL=
Comment 25 cno 2010-07-01 15:25:43 UTC
I think keywords here can be removed?
Comment 26 ooo 2010-07-01 16:57:31 UTC
Yes, no further locale info needed..
Comment 27 fyva 2011-01-25 10:11:11 UTC
>------- Additional comments from ab Wed Apr 18 14:04:51 +0000 2007 -------
>
>Thanks, Eike
>
>STARTED

This issue is started for almost 4 years. Are there any difficulties? Maybe, you
can reassign it to someone else?
Comment 28 Fredrik L 2016-10-15 06:07:30 UTC
This month it’s ten tears since this bug was first reported and I just want to confirm it is still present on:

AOO 4.1.3 on Linux Mint 18
AOO 4.1.2 on Manjaro Linux 16.08
AOO 4.0.1 on Sparky Linux 4.2

cDbl and cSng not working when using USA AOO with LC_NUMERIC="sv_SE.UTF-8”.
If it is changed into LC_NUMERIC="en_US.UTF-8" it is working.
Comment 29 Marcus 2017-05-20 11:00:59 UTC
Reset assigne to the default "issues@openoffice.apache.org".