diff options
author | Laurent Balland <laurent.balland@mailo.fr> | 2024-06-08 17:14:31 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2024-06-13 15:34:33 +0200 |
commit | bd2ffb6f33e549483b41f6235ba64fa735205d38 (patch) | |
tree | d1902e9c58b4444e514da9d4380a3af5dadea12d | |
parent | 542e590f6a35a350cb6bc53645462a273017258d (diff) |
tdf#159930 Treat special case with no integer digit
Number format with no integer digit, such as "+.##;-.##"
was placing string with the decimal separator.
This change insert string at the begining of the number string as
expected.
This format code is saved as "+#.##;-#.##" in ODF, but display is the
same; so no change is made on this side.
Add unit test for this format
Change-Id: I74fbe0e9a5303672ac7927d37922c06a762feba6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168577
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | svl/qa/unit/svl.cxx | 5 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 389195ec1728..3a8f5f51b43e 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -1823,6 +1823,11 @@ void Test::testUserDefinedNumberFormats() sExpected = "Value= 12,345.00"; checkPreviewString(aFormatter, sCode, 12345, LANGUAGE_ENGLISH_US, sExpected); } + { // tdf#159930 no digit in integer part + sCode = "+.000;-.000"; + sExpected = "+3.142"; // without the patch is would display "3+.142" + checkPreviewString(aFormatter, sCode, M_PI, LANGUAGE_ENGLISH_US, sExpected); + } } void Test::testNfEnglishKeywordsIntegrity() diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 855acc179d30..4975738df5c4 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -4682,6 +4682,12 @@ bool SvNumberformat::ImpNumberFillWithThousands( const NativeNumberWrapper& rNat aGrouping.reset(); [[fallthrough]]; case NF_SYMBOLTYPE_STRING: + if ( rInfo.nTypeArray[j] == NF_SYMBOLTYPE_STRING && nDigCnt == 0 ) + { + // tdf#159930 no integer in format ".###" + k = 0; // insert string at the beginning + } + [[fallthrough]]; case NF_SYMBOLTYPE_CURRENCY: case NF_SYMBOLTYPE_PERCENT: if ( rInfo.nTypeArray[j] != NF_SYMBOLTYPE_DECSEP || bAddDecSep ) |