Bug 162724 - CStr() and Format() should produce localized output for currency values
Summary: CStr() and Format() should produce localized output for currency values
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
24.8.0.3 release
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:25.2.0 target:24.8.2
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-31 12:54 UTC by rehierl
Modified: 2024-09-04 09:36 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Some sample code to reproduce the issue (1.28 KB, text/plain)
2024-08-31 12:56 UTC, rehierl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description rehierl 2024-08-31 12:54:33 UTC
Description:
I personally prefer to have an english user interface, while still being able to view values with localized formatting. This combination allowed me to stumble across the issue described below.

- menu / tools / options / languages and locales / general

With single and double values, it is possible to produce localized strings, and then reparse the original value from it. That however is no longer possible with currency values.

- x=CSng(1.5) : s=CStr(x) : y=CSng(s) '(y = x) is true
- x=CDbl(1.5) : s=CStr(x) : y=CDbl(s) '(y = x) is true
- x=CCur(1.5) : s=CStr(x) : y=CCur(s) 'CCur(s) throws an ERROR

For currency values, CStr(x) seems to produce culture invariant output (with "." as decimal separator, instead of "," as configured by my locale settings). That is in contrary to CStr(x) for single or double values.

Thus far, that behavior didn't seem to be much of an issue since CCur(s) was still able to reproduce the orginal currency value. However, some time after LibreOffice version 24.2.5.2 the behavior of CCur(s) must have been changed such that it now needs localized input to work. As a consequence, CStr() and Format() may produce output that CCur() fails to process.

VERSION: 24.8.0.3 (X86_64) / LibreOffice Community
LOCALE: de-DE (en_US.UTF-8); UI: en-US
SYSTEM: AppImage on Linux

- locale settings: english interface, german formatting
- CStr(value) produces "1.5000" - ERROR, should be localized
- Format(value, "General Number") - same result
- CCur("1.5000") produces an "inadmissible value" error - ERROR
- CCur("1,5") will return CCur(1.5) - THE ISSUE

VERSION: 7.3.7.2 / LibreOffice Community
LOCALE: de-DE (en_US.UTF-8); UI: en-US
SYSTEM: Preinstalled on Linux Mint

- locale settings: english interface, german formatting
- CStr(value) produces "1.5000" - ERROR, should be localized
- Format(value, "General Number") - same result
- CCur("1.5000") does work
- CCur("1,5") will return CCur(15)

VERSION: 24.2.5.2 (X86_64) / LibreOffice Community
LOCALE: de-DE (de_DE); UI: de-DE
SYSTEM: Windows 10 on a virtual machine

- locale settings: german interface, german formatting
- CStr(value) produces "1.5000" - ERROR, should be localized
- Format(value, "General Number") - same result
- CCur("1.5000") does work
- CCur("1,5") will return CCur(15)

SUMMARY
- CStr() and Format() will consistently produce localized
  output with single and double values.
- CSng() and CDbl() allow reproduce the original value
  from localized representations (round-trip is possible).
- CCur() now seems to expect localized input,
  which CStr() will not produce for currency values.
- CStr() and Format() continue to ignore locale settings
  for currency values (round-trip is broken).

POSSIBLE FIX
Change CStr() and Format() such that both produce localized output for currency values. This would re-enable round-trip conversions. Furthermore, these functions whould then show consistent behavior across single, double and currency values.



Steps to Reproduce:
As layed out in the description, and in the attached sample code.

Actual Results:
It is no longer possible to format a currency value using the CStr() or Format() function, and then expect CCur() to always reproduce the original value.

Expected Results:
A round-trip (format and reparse the original value) should always be possible. Furthermore, if CStr() produces localized output for single or double values, then - as a matter of consistency - CStr() should also produce localized output for currency values.


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 24.8.0.3 (X86_64) / LibreOffice Community
Build ID: 0bdf1299c94fe897b119f97f3c613e9dca6be583
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: de-DE (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 rehierl 2024-08-31 12:56:03 UTC
Created attachment 196133 [details]
Some sample code to reproduce the issue
Comment 2 Mike Kaganski 2024-08-31 14:11:52 UTC
The change happened in commit 9cc8457abcae57c7f9de6e0fbca1fbc2a0cc9892 (tdf#128122 Updated BASIC CCur to reuse SvNumberFormatter).
Comment 4 Mike Kaganski 2024-08-31 15:09:55 UTC
https://gerrit.libreoffice.org/c/core/+/172693
Comment 5 Commit Notification 2024-09-01 02:07:01 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a795fddafad69e8a7ce600352c7236b35539cebb

tdf#162724: use localized decimal separator in ImpCurrencyToString

It will be available in 25.2.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 6 Commit Notification 2024-09-04 09:36:32 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/74a68f76bb116e348826bff912d52d8205ab92a3

tdf#162724: use localized decimal separator in ImpCurrencyToString

It will be available in 24.8.2.

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.