diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2016-06-25 22:27:11 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-06-29 18:31:23 +0000 |
commit | 97fda453bc43fbae3d0a9fd05259e92d3205fd06 (patch) | |
tree | a52572fed79302b8b9cdf61aa5b82c8ed802bfab /svl/source | |
parent | b3bba0b8452d1e5798bd01f09a642718bcecf30f (diff) |
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@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'svl/source')
-rw-r--r-- | svl/source/numbers/zformat.cxx | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index a80fc5360f24..8a028857e0c9 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; |