diff options
author | Laurent Balland <laurent.balland@mailo.fr> | 2023-03-19 21:45:52 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-04-06 18:00:12 +0200 |
commit | dc9b8c31aaf72812dc205f610638098898a4cde7 (patch) | |
tree | f8d4d9f8b0c21aeb59d4a488d2c59c2a5386d4d6 /svl/source/numbers | |
parent | 74d39f5cff324d76092268418028bd882d8a4d60 (diff) |
tdf#153887 Fraction number format: avoid 0/0
If round value is an integer and there is no integer part in the number
format, then nDiv was wrongly forced to 0.
Add corresponding unit tests.
Change-Id: Ib69393eca8f6c2bdda0eacfc83637ab0c971ff2d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149118
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'svl/source/numbers')
-rw-r--r-- | svl/source/numbers/zformat.cxx | 8 |
1 files changed, 5 insertions, 3 deletions
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; } } |