summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-02-15 22:01:51 +0100
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2017-02-16 11:00:26 +0000
commit8e3ad5f11401a337910c6d63263811ca66ba456c (patch)
tree19411aa0ec6a25c59319b843138e6bd8cfad5ff6 /svl
parentba8ac3843790226385e55bdf222de0d3aecc281d (diff)
Resolves: tdf#105968 handle engineering notation rounded into next magnitude
Change-Id: Ie31ab88543994f0e8aeef8152c230c05e071ef8e (cherry picked from commit 63bc2b13cb344cce99348496838d7d2c2f690211) Reviewed-on: https://gerrit.libreoffice.org/34321 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zformat.cxx11
1 files changed, 11 insertions, 0 deletions
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 8178b7e4e385..ac0c6080ee4c 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2593,11 +2593,22 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber,
nExpSign = 1;
}
ExpStr = OUString::number( nExp );
+ const sal_Unicode cFirstDigit = sStr[0];
// rescale mantissa
sStr = ::rtl::math::doubleToUString( fNumber,
rtl_math_StringFormat_E,
nRescale + rInfo.nCntPost, '.' );
+
+ // sStr now may contain a rounded-up value shifted into the next
+ // magnitude, for example 1.000E+02 (4 digits) for fNumber 99.995
+ // (9.9995E+02 rounded to 3 decimals) but we want the final result
+ // to be 100.00E+00 (5 digits), so for the following fill routines
+ // below to work correctly append a zero decimal.
+ /* TODO: this is awkward, could an engineering notation mode be
+ * introduced to rtl_math_doubleToUString()? */
sStr.truncate( sStr.indexOf('E') );
+ if (sStr[0] == '1' && cFirstDigit != '1')
+ sStr.append('0');
}
// cut any decimal delimiter