diff options
-rw-r--r-- | svl/qa/unit/svl.cxx | 12 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 557c9be639e6..06d018f3b624 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -1449,6 +1449,18 @@ void Test::testUserDefinedNumberFormats() sExpected = "-575 540/697"; checkPreviewString(aFormatter, sCode, -575.774749601315, eLang, sExpected); } + { // tdf#153887: integer value without integer part displayed + sCode = "#/?"; + sExpected = "2/1"; + checkPreviewString(aFormatter, sCode, 1.95, eLang, sExpected); + checkPreviewString(aFormatter, sCode, 2.00, eLang, sExpected); + checkPreviewString(aFormatter, sCode, 2.05, eLang, sExpected); + sCode = "0/8"; + sExpected = "16/8"; + checkPreviewString(aFormatter, sCode, 1.95, eLang, sExpected); + checkPreviewString(aFormatter, sCode, 2.00, eLang, sExpected); + checkPreviewString(aFormatter, sCode, 2.05, eLang, sExpected); + } { // tdf#102507: left alignment of denominator sCode = "# ?/???"; sExpected = "3 1/2 "; diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 676692da6fdb..5128c5cca118 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -2830,9 +2830,10 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, fIntPart = floor(fNumber); // Integral part fNumber -= fIntPart; // Fractional part const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - nDiv = lcl_GetDenominatorString( rInfo, NumFor[nIx].GetCount() ).toInt32(); - if( nDiv > 0 ) + sal_Int64 nForcedDiv = lcl_GetDenominatorString( rInfo, NumFor[nIx].GetCount() ).toInt32(); + if( nForcedDiv > 0 ) { // Forced Denominator + nDiv = nForcedDiv; nFrac = static_cast<sal_Int64>(floor ( fNumber * nDiv )); double fFracNew = static_cast<double>(nFrac) / static_cast<double>(nDiv); double fFracNew1 = static_cast<double>(nFrac + 1) / static_cast<double>(nDiv); @@ -2886,7 +2887,8 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, if (nFrac >= nDiv) { ++fIntPart; - nFrac = nDiv = 0; + nFrac = 0; + nDiv = ( nForcedDiv > 0 ) ? nForcedDiv : 1; } } |