[Libreoffice-commits] core.git: 2 commits - svl/qa svl/source
Eike Rathke
erack at redhat.com
Wed Feb 15 21:06:25 UTC 2017
svl/qa/unit/svl.cxx | 35 +++++++++++++++++++++++++++++++++++
svl/source/numbers/zformat.cxx | 11 +++++++++++
2 files changed, 46 insertions(+)
New commits:
commit 5e180078ecc4501900e41da48b279033a7529a96
Author: Eike Rathke <erack at redhat.com>
Date: Wed Feb 15 22:05:29 2017 +0100
unit test for engineering notation, tdf#105968
Change-Id: Ib5303f09cfda232b0bee88df3d76650165337c08
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 9804c7e..8e185d5 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -1221,6 +1221,41 @@ void Test::testUserDefinedNumberFormats()
sCode = "[DBNum2][$-0404]General\\ ";
checkPreviewString(aFormatter, sCode, 120, eLang, sExpected);
}
+ { // tdf#105968 engineering format with value rounded up to next magnitude
+ sCode = "##0.00E+00";
+ sExpected = "100.00E+00";
+ checkPreviewString(aFormatter, sCode, 99.995, eLang, sExpected);
+ // test '1'=='1' assumption
+ checkPreviewString(aFormatter, sCode, 100.0, eLang, sExpected);
+ sExpected = "199.99E+00";
+ checkPreviewString(aFormatter, sCode, 199.99, eLang, sExpected);
+ sExpected = "1.00E+03";
+ checkPreviewString(aFormatter, sCode, 1000.0, eLang, sExpected);
+ // and another just "normally" rounded value
+ sExpected = "894.55E-06";
+ checkPreviewString(aFormatter, sCode, 0.000894549, eLang, sExpected);
+ // not expecting rounding into another magnitude
+ sExpected = "999.99E-06";
+ checkPreviewString(aFormatter, sCode, 0.000999991, eLang, sExpected);
+ // expecting rounding into another magnitude
+ sExpected = "1.00E-03";
+ checkPreviewString(aFormatter, sCode, 0.000999999, eLang, sExpected);
+
+ // Now the same all negative values.
+ sExpected = "-100.00E+00";
+ checkPreviewString(aFormatter, sCode, -99.995, eLang, sExpected);
+ checkPreviewString(aFormatter, sCode, -100.0, eLang, sExpected);
+ sExpected = "-199.99E+00";
+ checkPreviewString(aFormatter, sCode, -199.99, eLang, sExpected);
+ sExpected = "-1.00E+03";
+ checkPreviewString(aFormatter, sCode, -1000.0, eLang, sExpected);
+ sExpected = "-894.55E-06";
+ checkPreviewString(aFormatter, sCode, -0.000894549, eLang, sExpected);
+ sExpected = "-999.99E-06";
+ checkPreviewString(aFormatter, sCode, -0.000999991, eLang, sExpected);
+ sExpected = "-1.00E-03";
+ checkPreviewString(aFormatter, sCode, -0.000999999, eLang, sExpected);
+ }
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
commit 63bc2b13cb344cce99348496838d7d2c2f690211
Author: Eike Rathke <erack at redhat.com>
Date: Wed Feb 15 22:01:51 2017 +0100
Resolves: tdf#105968 handle engineering notation rounded into next magnitude
Change-Id: Ie31ab88543994f0e8aeef8152c230c05e071ef8e
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 8178b7e..ac0c608 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
More information about the Libreoffice-commits
mailing list