|
|
97ee054 |
From 1ce01e210deb636f62688f9c41112a4f46948976 Mon Sep 17 00:00:00 2001
|
|
|
97ee054 |
Message-Id: <1ce01e210deb636f62688f9c41112a4f46948976.1443537351.git.erack@redhat.com>
|
|
|
97ee054 |
From: Eike Rathke <erack@redhat.com>
|
|
|
97ee054 |
Date: Tue, 29 Sep 2015 15:54:19 +0200
|
|
|
97ee054 |
Subject: [PATCH] use exponential 'E' format for General when appropriate
|
|
|
97ee054 |
MIME-Version: 1.0
|
|
|
97ee054 |
Content-Type: multipart/mixed; boundary="------------erAck-patch-parts"
|
|
|
97ee054 |
|
|
|
97ee054 |
This is a multi-part message in MIME format.
|
|
|
97ee054 |
--------------erAck-patch-parts
|
|
|
97ee054 |
Content-Type: text/plain; charset=UTF-8; format=fixed
|
|
|
97ee054 |
Content-Transfer-Encoding: 8bit
|
|
|
97ee054 |
|
|
|
97ee054 |
|
|
|
97ee054 |
Fixes all these test case scenarios:
|
|
|
97ee054 |
1. in A1 enter =1E222
|
|
|
97ee054 |
* move cell cursor back onto A1
|
|
|
97ee054 |
* status bar displays Sum=100000... repeated until
|
|
|
97ee054 |
filled (or 222 '0' characters)
|
|
|
97ee054 |
2. invoke number format dialog on A1
|
|
|
97ee054 |
* for General format 100000... is displayed in the preview
|
|
|
97ee054 |
3. move cell cursor to A2
|
|
|
97ee054 |
* open Function Wizard (Ctrl+F2)
|
|
|
97ee054 |
* choose (double click) ABS function
|
|
|
97ee054 |
* enter A1 as parameter
|
|
|
97ee054 |
* see 100000... displayed as Function result and Result
|
|
|
97ee054 |
4. save as .ods
|
|
|
97ee054 |
* in content.xml see display text of A1 being saved as 100000...
|
|
|
97ee054 |
|
|
|
97ee054 |
(cherry picked from commit ef0a26835e68deb31906c40cfe48c66674d9d0d1)
|
|
|
97ee054 |
|
|
|
97ee054 |
Conflicts:
|
|
|
97ee054 |
svl/source/numbers/zformat.cxx
|
|
|
97ee054 |
|
|
|
97ee054 |
Change-Id: I7c22c0461a6783c85c1d51c31e8607fb2edb821c
|
|
|
97ee054 |
---
|
|
|
97ee054 |
svl/source/numbers/zformat.cxx | 52 ++++++++++++++++++++++++++++--------------
|
|
|
97ee054 |
1 file changed, 35 insertions(+), 17 deletions(-)
|
|
|
97ee054 |
|
|
|
97ee054 |
|
|
|
97ee054 |
--------------erAck-patch-parts
|
|
|
97ee054 |
Content-Type: text/x-patch; name="0001-use-exponential-E-format-for-General-when-appropriat.patch"
|
|
|
97ee054 |
Content-Transfer-Encoding: 8bit
|
|
|
97ee054 |
Content-Disposition: attachment; filename="0001-use-exponential-E-format-for-General-when-appropriat.patch"
|
|
|
97ee054 |
|
|
|
97ee054 |
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
|
|
|
97ee054 |
index a48c029..92c52f4 100644
|
|
|
97ee054 |
--- a/svl/source/numbers/zformat.cxx
|
|
|
97ee054 |
+++ b/svl/source/numbers/zformat.cxx
|
|
|
97ee054 |
@@ -60,6 +60,11 @@ struct Gregorian : public rtl::StaticWithInit<const OUString, Gregorian>
|
|
|
97ee054 |
|
|
|
97ee054 |
const sal_uInt16 UPPER_PRECISION = 300; // entirely arbitrary...
|
|
|
97ee054 |
const double EXP_LOWER_BOUND = 1.0E-4; // prefer scientific notation below this value.
|
|
|
97ee054 |
+const double EXP_ABS_UPPER_BOUND = 1.0E15; // use exponential notation above that absolute value.
|
|
|
97ee054 |
+ // Back in time was E16 that lead
|
|
|
97ee054 |
+ // to display rounding errors, see
|
|
|
97ee054 |
+ // also sal/rtl/math.cxx
|
|
|
97ee054 |
+ // doubleToString()
|
|
|
97ee054 |
|
|
|
97ee054 |
} // namespace
|
|
|
97ee054 |
|
|
|
97ee054 |
@@ -2125,7 +2130,7 @@ void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& OutString)
|
|
|
97ee054 |
{
|
|
|
97ee054 |
sal_uInt16 nStandardPrec = rScan.GetStandardPrec();
|
|
|
97ee054 |
|
|
|
97ee054 |
- if ( fabs(fNumber) > 1.0E15 ) // #58531# was E16
|
|
|
97ee054 |
+ if ( fabs(fNumber) > EXP_ABS_UPPER_BOUND )
|
|
|
97ee054 |
{
|
|
|
97ee054 |
nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals
|
|
|
97ee054 |
OutString = ::rtl::math::doubleToUString( fNumber,
|
|
|
97ee054 |
@@ -2513,27 +2518,40 @@ bool SvNumberformat::GetOutputString(double fNumber,
|
|
|
97ee054 |
}
|
|
|
97ee054 |
fNumber = -fNumber;
|
|
|
97ee054 |
}
|
|
|
97ee054 |
+ /* TODO: why did we insist on 10 decimals for the non-exponent
|
|
|
97ee054 |
+ * case? doubleToUString() handles rtl_math_DecimalPlaces_Max
|
|
|
97ee054 |
+ * gracefully when used with rtl_math_StringFormat_Automatic,
|
|
|
97ee054 |
+ * so all that special casing and mumbo-jumbo in the else
|
|
|
97ee054 |
+ * branch below might not be needed at all. */
|
|
|
97ee054 |
+ if (fNumber > EXP_ABS_UPPER_BOUND)
|
|
|
97ee054 |
+ {
|
|
|
97ee054 |
+ sBuff.append( ::rtl::math::doubleToUString( fNumber,
|
|
|
97ee054 |
+ rtl_math_StringFormat_Automatic,
|
|
|
97ee054 |
+ rtl_math_DecimalPlaces_Max,
|
|
|
97ee054 |
+ GetFormatter().GetNumDecimalSep()[0], true));
|
|
|
97ee054 |
+ }
|
|
|
97ee054 |
+ else
|
|
|
97ee054 |
{
|
|
|
97ee054 |
OUString sTemp;
|
|
|
97ee054 |
ImpGetOutputStdToPrecision(fNumber, sTemp, 10); // Use 10 decimals for general 'unlimited' format.
|
|
|
97ee054 |
sBuff.append(sTemp);
|
|
|
97ee054 |
- }
|
|
|
97ee054 |
- if (fNumber < EXP_LOWER_BOUND)
|
|
|
97ee054 |
- {
|
|
|
97ee054 |
- sal_Int32 nLen = sBuff.getLength();
|
|
|
97ee054 |
- if (!nLen)
|
|
|
97ee054 |
+ if (fNumber < EXP_LOWER_BOUND)
|
|
|
97ee054 |
{
|
|
|
97ee054 |
- return false;
|
|
|
97ee054 |
- }
|
|
|
97ee054 |
- // #i112250# With the 10-decimal limit, small numbers are formatted as "0".
|
|
|
97ee054 |
- // Switch to scientific in that case, too:
|
|
|
97ee054 |
- if (nLen > 11 || ((nLen == 1 && sBuff[0] == '0') && fNumber != 0.0))
|
|
|
97ee054 |
- {
|
|
|
97ee054 |
- sal_uInt16 nStandardPrec = rScan.GetStandardPrec();
|
|
|
97ee054 |
- nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals
|
|
|
97ee054 |
- sBuff = ::rtl::math::doubleToUString( fNumber,
|
|
|
97ee054 |
- rtl_math_StringFormat_E, nStandardPrec /*2*/,
|
|
|
97ee054 |
- GetFormatter().GetNumDecimalSep()[0], true);
|
|
|
97ee054 |
+ sal_Int32 nLen = sBuff.getLength();
|
|
|
97ee054 |
+ if (!nLen)
|
|
|
97ee054 |
+ {
|
|
|
97ee054 |
+ return false;
|
|
|
97ee054 |
+ }
|
|
|
97ee054 |
+ // #i112250# With the 10-decimal limit, small numbers are formatted as "0".
|
|
|
97ee054 |
+ // Switch to scientific in that case, too:
|
|
|
97ee054 |
+ if (nLen > 11 || ((nLen == 1 && sBuff[0] == '0') && fNumber != 0.0))
|
|
|
97ee054 |
+ {
|
|
|
97ee054 |
+ sal_uInt16 nStandardPrec = rScan.GetStandardPrec();
|
|
|
97ee054 |
+ nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals
|
|
|
97ee054 |
+ sBuff = ::rtl::math::doubleToUString( fNumber,
|
|
|
97ee054 |
+ rtl_math_StringFormat_E, nStandardPrec /*2*/,
|
|
|
97ee054 |
+ GetFormatter().GetNumDecimalSep()[0], true);
|
|
|
97ee054 |
+ }
|
|
|
97ee054 |
}
|
|
|
97ee054 |
}
|
|
|
97ee054 |
if (bSign)
|
|
|
97ee054 |
|
|
|
97ee054 |
--------------erAck-patch-parts--
|
|
|
97ee054 |
|
|
|
97ee054 |
|