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
This commit is contained in:
Laurent Balland
2024-06-13 15:34:33 +02:00
committed by Eike Rathke
parent 542e590f6a
commit bd2ffb6f33
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -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()
+6
View File
@@ -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 )