Bug 98778 - String to numeric conversion fails when number is formatted as scientific notation
Summary: String to numeric conversion fails when number is formatted as scientific not...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.3.0.4 release
Hardware: All All
: medium normal
Assignee: Caolán McNamara
QA Contact:
URL:
Whiteboard: target:5.3.0 target:5.2.1 target:5.1....
Keywords: regression
: 93193 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-03-20 01:28 UTC by indexel
Modified: 2016-10-21 14:53 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description indexel 2016-03-20 01:28:55 UTC
When assigning a string variable containing a number formatted as scientific notation, to a double variable, the conversion fails and zero is assigned. See example code below:


Sub Main
 dim d as double
 dim s as string
 s="1.0E-5"
 d=s
 msgbox "Value of d is: "+str(d)
End Sub

However, if s is set equal to "0.00001" then it works correctly. A workaround is to use the val() function, but this often requires numerous changes to legacy code that worked fine in OpenOffice Basic.

I haven't checked any versions earlier than the one listed here (4.4.7.2). So, I don't know how far back this problem existed.
Comment 1 raal 2016-03-20 11:43:43 UTC
reproducible with Version: 5.2.0.0.alpha0+ (x64) and Version: 4.3.0.0.alpha1+

LO 3.5:   value of d is:1 - not correct result.
OpenOffice 4.1.2:   value of d is:1.0E-5 - correct result
Comment 2 Bernard Marcelly 2016-03-21 07:48:07 UTC
There is also a related bug with CDbl() and CSng() converting a string with scientific notation.
These functions convert using the locale decimal separator, so I use a localized string to work for any value.

dim d as double
dim s1 as string

s1 = 1.0e-5 ' implicit conversion to string
msgbox s1 ' the string is correct

d = CDbl(s1) ' error : data type mismatch
msgbox d

dim sf as single
sf = CSng(s1) ' error : data type mismatch
msgbox sf
Comment 3 Caolán McNamara 2016-07-20 15:22:08 UTC
This appears to have gone wrong with...

commit 9e9f39d171cafa035d7b8e74187e25c3581cb89d
Author: Eike Rathke <erack@redhat.com>
Date:   Tue Mar 19 23:23:16 2013 +0100

    resolved rhbz#919020 Basic CDbl() and CSng() scan localized number
Comment 4 Caolán McNamara 2016-07-20 15:33:02 UTC
https://gerrit.libreoffice.org/#/c/27342/ makes it work for me
Comment 5 Caolán McNamara 2016-07-20 15:37:47 UTC
*** Bug 93193 has been marked as a duplicate of this bug. ***
Comment 6 Commit Notification 2016-07-20 15:56:23 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=2aed0d49d7891b9360916b65771222810aeeac96

Resolves: tdf#98778 fix parsing of exponents

It will be available in 5.3.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 7 Commit Notification 2016-07-20 15:58:57 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-5-2":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=ff5e57d2292b548d7f8607c47a38d9e39753d5fa&h=libreoffice-5-2

Resolves: tdf#98778 fix parsing of exponents

It will be available in 5.2.1.

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

Affected users are encouraged to test the fix and report feedback.
Comment 8 Commit Notification 2016-07-20 16:00:22 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-5-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=43d1f9bfd4300e8bf5bcb631dcc2d849b4490d3a&h=libreoffice-5-1

Resolves: tdf#98778 fix parsing of exponents

It will be available in 5.1.6.

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

Affected users are encouraged to test the fix and report feedback.
Comment 9 Commit Notification 2016-07-21 14:11:52 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-5-1-5":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=a6649901d3e01b3751b3e1660ac29b2248bf3c25&h=libreoffice-5-1-5

Resolves: tdf#98778 fix parsing of exponents

It will be available in 5.1.5.

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

Affected users are encouraged to test the fix and report feedback.
Comment 10 Commit Notification 2016-07-22 08:54:28 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-5-2-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=854e4a714d9abea5d66ed34f73f1b05c06b62b86&h=libreoffice-5-2-0

Resolves: tdf#98778 fix parsing of exponents

It will be available in 5.2.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 11 pierre-yves samyn 2016-10-21 14:53:49 UTC
Hi

Verified on windows 7/64 & Version: 5.3.0.0.alpha1+
Build ID: 8a796410ec8f440b4163b15b928347c499da7a8f
CPU Threads: 2; OS Version: Windows 6.1; UI Render: default; 
TinderBox: Win-x86@42, Branch:master, Time: 2016-10-20_23:07:21
Locale: fr-FR (fr_FR); Calc: group

Thank you

Regards
Pierre-Yves