Download it now!
Bug 97983 - cInt function treats , as decimal
Summary: cInt function treats , as decimal
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.5.0 release
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:6.5.0
Keywords:
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
 
Reported: 2016-02-18 15:58 UTC by tim
Modified: 2019-12-02 20:40 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Demonstration Writer document with macro (9.98 KB, application/vnd.oasis.opendocument.text)
2016-02-18 15:58 UTC, tim
Details
test cInt (9.91 KB, application/vnd.oasis.opendocument.spreadsheet)
2019-12-02 18:33 UTC, Oliver Brinzing
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tim 2016-02-18 15:58:21 UTC
Created attachment 122772 [details]
Demonstration Writer document with macro

The cInt function treats string "1,234" as being 1.  This is true on 3 different operating systems on 2 different PCs, all of which are defined as being in the EN GB locale using '.' as the decimal point in the language settings (I have double-checked this).

I have tested this on:

ubuntu 14.04 64 bit, Version: 5.1.1.1 Build ID: 1:5.1.1~rc1-0ubuntu1~trusty1 CPU Threads: 8; OS Version: Linux 4.2; UI Render: default; Locale: en-GB (en_GB.UTF-8) (from ubuntu pre-release PPA)

Windows 7 (on same PC) Version 5.0.4.2 (from Libreoffice website)

xubuntu 15.04 (a 64 bit laptop), Version 5.0.5.2 Build ID: 1.5.0.5-rc2-0ubuntu2 Locale en:GB (en GB.UTF-8) (from ubuntu release PPA)

I don't how far back this issue goes.  It's easy to work-around, just use format to remove the ','s, but could fool people for a long time if in the middle of a complex algorithm.

I attach a Writer document demonstrating this. Press the button to see what "1,234" turns into.  The macro is in 'Module1', 'Main', and just says:

Sub Main
	Dim sText as String
	Dim iIntText as Integer
	sText = "1,234"
	iIntText = cInt (sText)
	MsgBox "1,234 becomes" & iIntText
End Sub

I originally found this using Basic in Base.  I thought I'd demonstrate it in Writer just to show it was nothing to do with Base.

Or am I being really stupid?
Comment 1 Buovjaga 2016-02-20 15:53:46 UTC
Repro.

Win 7 Pro 64-bit, Version: 5.1.0.3 (x64)
Build ID: 5e3e00a007d9b3b6efb6797a8b8e57b51ab1f737
CPU Threads: 4; OS Version: Windows 6.1; UI Render: default; 
Locale: fi-FI (fi_FI)

LibreOffice 3.5.0rc3 
Build ID: 7e68ba2-a744ebf-1f241b7-c506db1-7d53735
Comment 2 tim 2016-02-20 15:57:32 UTC
I have tried to verify that my understanding of the correct behaviour of cInt is correct.  I've not found any absolutely definitive source, although several websites recommend using it as opposed to 'Val' because it tolerates regional variations better.
Comment 3 tim 2016-02-20 16:06:00 UTC
(In reply to tim from comment #2)
> I have tried to verify that my understanding of the correct behaviour of
> cInt is correct.  I've not found any absolutely definitive source, although
> several websites recommend using it as opposed to 'Val' because it tolerates
> regional variations better.
I just found this:
http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs79.htm

Which claims to be from Microsoft for Visual Basic.  It says:

 "Use the CInt function to provide internationally aware conversions from any other data type to an Integer subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators."
Comment 4 QA Administrators 2017-03-06 15:51:32 UTC Comment hidden (obsolete)
Comment 5 tim 2017-03-06 16:55:31 UTC
The bug is still present on 64 bit ubuntu 16.10, librefoffice:

Version: 5.3.1.1
Build ID: 1:5.3.1~rc1-0ubuntu1~yakkety0
CPU Threads: 8; OS Version: Linux 4.8; UI Render: default; VCL: x11; Layout Engine: new; 
Locale: en-GB (en_GB.UTF-8); Calc: group

All Language Settings are set to GB.
Comment 6 QA Administrators 2018-03-07 03:41:54 UTC Comment hidden (obsolete)
Comment 7 tim 2018-03-07 07:52:39 UTC
Retested under Version: 6.0.2.1
Build ID: 1:6.0.2~rc1-0ubuntu0.17.10.1~lo1
CPU threads: 8; OS: Linux 4.13; UI render: GL; VCL: gtk2; 
Locale: en-GB (en_GB.UTF-8); Calc: group

The behaviour is unchanged. 1,234 is still transformed to be 1 (rather than 1234), regardless of the fact that I am in the UK, with UK settings.
Comment 8 QA Administrators 2019-03-08 03:41:07 UTC Comment hidden (obsolete)
Comment 9 tim 2019-03-08 09:48:04 UTC
The bug is still present on:

Version: 6.1.5.2
Build ID: 1:6.1.5~rc2-0ubuntu0.18.10.1~lo3
CPU threads: 8; OS: Linux 4.18; UI render: default; VCL: x11; 
Locale: en-GB (en_GB.UTF-8); Calc: group threaded
Comment 10 Commit Notification 2019-11-28 09:22:22 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4fdc90c51e6a1bbb83c1f1826ad5b90dc1ff0ad6

tdf#97983 - Added localization for numeric types

It will be available in 6.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Buovjaga 2019-12-01 15:46:15 UTC
Andreas: thanks for working on this. However, I still get "1,234 becomes1" when I press the button in the example document.

Arch Linux 64-bit
Version: 6.5.0.0.alpha0+
Build ID: 7e403195e574be5174815a51cf5c42f06f76a87a
CPU threads: 8; OS: Linux 5.3; UI render: default; VCL: kf5; 
Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
Calc: threaded
Built on 1 December 2019
Comment 12 Andreas Heinisch 2019-12-01 17:15:56 UTC
Yes I see, I missed some of the functions without a standard parameter, I will send a follow up patch tomorrow. Thank you for the test!
Comment 13 Andreas Heinisch 2019-12-02 10:45:07 UTC
Hm, just a stupid question: with your locale (Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US) this example should return 1 and for an an English locale the example will return 1234. So I think the patch is correct.
Comment 14 Buovjaga 2019-12-02 11:26:48 UTC
(In reply to Andreas Heinisch from comment #13)
> Hm, just a stupid question: with your locale (Locale: fi-FI (fi_FI.UTF-8);
> UI-Language: en-US) this example should return 1 and for an an English
> locale the example will return 1234. So I think the patch is correct.

Argh, sorry, you are right. I tested by running with LC_ALL=C and indeed I get "1,234 becomes1234" with en-US locale.
Comment 15 Oliver Brinzing 2019-12-02 18:33:26 UTC
Created attachment 156252 [details]
test cInt

Please add an entry to the release notes, cause this change can affect existing basic code.
Comment 16 Andreas Heinisch 2019-12-02 20:40:34 UTC
Thank you for the hint! Done:
https://wiki.documentfoundation.org/ReleaseNotes/6.5#Base