[Libreoffice-commits] core.git: svl/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Sun May 23 14:24:46 UTC 2021


 svl/source/numbers/zformat.cxx |   35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

New commits:
commit 172d5649106d8602ee258b7002b78459edd4855c
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Sun May 23 13:52:05 2021 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Sun May 23 16:24:10 2021 +0200

    Resolves: tdf#137063 For General format start exponential display at 1E-10
    
    ... instead of 1E-05, if not too many significant digits.
    
    Change-Id: I66cca1bdd2742526e4ade08a691e6d43b2eb439e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116016
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 648034f9352a..19ee2134df35 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2489,18 +2489,33 @@ bool SvNumberformat::GetOutputString(double fNumber,
                 {
                     OutString = "0";
                 }
-                else if (fNumber < EXP_LOWER_BOUND && fNumber > -EXP_LOWER_BOUND)
-                {
-                    OutString = ::rtl::math::doubleToUString( fNumber,
-                                rtl_math_StringFormat_E2,
-                                15,
-                                GetFormatter().GetNumDecimalSep()[0], true);
-                }
                 else if (fNumber < 1.0 && fNumber > -1.0)
                 {
-                    OutString = ::rtl::math::doubleToUString( fNumber,
-                                rtl_math_StringFormat_Automatic,
-                                15,
+                    // Decide whether to display as 0.000000123... or 1.23...e-07
+                    bool bFix = (fNumber < -EXP_LOWER_BOUND || EXP_LOWER_BOUND < fNumber);
+                    if (!bFix)
+                    {
+                        // Arbitrary, not too many 0s visually, start E2 at 1E-10.
+                        constexpr sal_Int32 kMaxExp = 9;
+                        const sal_Int32 nExp = static_cast<sal_Int32>(ceil( -log10( fabs( fNumber))));
+                        if (nExp <= kMaxExp && rtl::math::approxEqual(
+                                    rtl::math::round( fNumber, 16), rtl::math::round( fNumber, nExp + 16)))
+                        {
+                            // Not too many significant digits or accuracy
+                            // artefacts, otherwise leave everything to E2
+                            // format.
+                            bFix = true;
+                        }
+                    }
+                    if (bFix)
+                        OutString = ::rtl::math::doubleToUString( fNumber,
+                                rtl_math_StringFormat_F,
+                                rtl_math_DecimalPlaces_Max,
+                                GetFormatter().GetNumDecimalSep()[0], true);
+                    else
+                        OutString = ::rtl::math::doubleToUString( fNumber,
+                                rtl_math_StringFormat_E2,
+                                rtl_math_DecimalPlaces_Max,
                                 GetFormatter().GetNumDecimalSep()[0], true);
                 }
                 else


More information about the Libreoffice-commits mailing list