[Libreoffice-commits] core.git: svl/source
Laurent Balland-Poirier
laurent.balland-poirier at laposte.net
Wed Jun 29 18:31:51 UTC 2016
svl/source/numbers/zformat.cxx | 29 ++++++++++-------------------
1 file changed, 10 insertions(+), 19 deletions(-)
New commits:
commit 97fda453bc43fbae3d0a9fd05259e92d3205fd06
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date: Sat Jun 25 22:27:11 2016 +0200
tdf#100594 Calculate nFrac with fNumber for Forced Denominator
nFrac was calculated with fraction value = nFrac/nDiv which could be rounded
in case of few digits in nDiv
Change-Id: I568121b0e7b5ea0b67bbff7bbbb37d2c272c3691
Reviewed-on: https://gerrit.libreoffice.org/26663
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Eike Rathke <erack at redhat.com>
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index a80fc53..8a02885 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2042,23 +2042,6 @@ OUString lcl_GetNumeratorString(const ImpSvNumberformatInfo &rInfo, sal_uInt16 n
return aNumeratorString.makeStringAndClear();
}
-// TODO: More optimizations?
-void lcl_ForcedDenominator(sal_uLong &nFrac, sal_uLong &nDiv, sal_uLong nForcedDiv)
-{
- double fFrac = (double)nFrac / (double)nDiv;
- double fMultiplier = (double)nForcedDiv / (double)nDiv;
- nFrac = (sal_uLong)( (double)nFrac * fMultiplier );
-
- double fFracNew = (double)nFrac / (double)nForcedDiv;
- double fFracNew1 = (double)(nFrac + 1) / (double)nForcedDiv;
- double fDiff = fFrac - fFracNew;
- if( fDiff > ( fFracNew1 - fFrac ) )
- {
- nFrac++;
- }
- nDiv = nForcedDiv;
-}
-
}
OUString SvNumberformat::GetDenominatorString( sal_uInt16 nNumFor ) const
@@ -2644,9 +2627,17 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber,
}
}
- if( sal_Int32 nForcedDiv = lcl_GetDenominatorString(NumFor[nIx].Info(), nAnz).toInt32() )
+ if( sal_Int32 nForcedDiv = lcl_GetDenominatorString(rInfo, nAnz).toInt32() )
{
- lcl_ForcedDenominator(nFrac, nDiv, nForcedDiv);
+ nDiv = (sal_uLong) nForcedDiv;
+ nFrac = (sal_uLong)floor ( fNumber * nDiv );
+ double fFracNew = (double)nFrac / (double)nDiv;
+ double fFracNew1 = (double)(nFrac + 1) / (double)nDiv;
+ double fDiff = fNumber - fFracNew;
+ if( fDiff > ( fFracNew1 - fNumber ) )
+ {
+ nFrac++;
+ }
if( nFrac >= nDiv )
{
nFrac = nDiv = 0;
More information about the Libreoffice-commits
mailing list