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

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Mon Mar 23 02:23:25 PDT 2015


 basic/qa/vba_tests/format.vb   |    4 ++--
 svl/source/numbers/zformat.cxx |   25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 10 deletions(-)

New commits:
commit 86a318ce629fbddb442f8f8ca762eeb3a51c9c6e
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Tue Mar 17 10:53:31 2015 +0100

    tdf#30716 Engineering notation
    
    Implement engineering notation: fomat ##0.00E+00 for instance
    Saved in ODF thanks to https://gerrit.libreoffice.org/14875/
    
    Change-Id: I1e401183a95ce05481a9af52e49bbcfe08cd1a20
    Reviewed-on: https://gerrit.libreoffice.org/14886
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/basic/qa/vba_tests/format.vb b/basic/qa/vba_tests/format.vb
index b4f1928..54b5610 100644
--- a/basic/qa/vba_tests/format.vb
+++ b/basic/qa/vba_tests/format.vb
@@ -296,8 +296,8 @@ Sub Custom_Number_Format_Sample()
     TestLog_ASSERT TestStr = "1,000,000", "#,###: " & TestStr
     'MsgBox TestStr
     
-    TestStr = Format(1.09837555, "######E-###") '109838E-5
-    TestLog_ASSERT TestStr = "109838E-5", "######E-###: " & TestStr
+    TestStr = Format(1.09837555, "######E-###") '109838E-5 => 1E0 with engineering notation
+    TestLog_ASSERT TestStr = "1E0", "######E-###: " & TestStr
     'MsgBox TestStr
     
     TestStr = Format(2345.25, "$#,###.##") '$2.345.25
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index e273484..41a99e8 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2296,18 +2296,14 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber,
         }
         ExpStr = sStr.toString().copy( nExpStart );    // part following the "E+"
         sStr.truncate( nExPos );
-        // cut any decimal delimiter
-        sal_Int32 index = 0;
 
-        while((index = sStr.indexOf('.', index)) >= 0)
-        {
-            sStr.remove(index, 1);
-        }
         if ( rInfo.nCntPre != 1 ) // rescale Exp
         {
             sal_Int32 nExp = ExpStr.toString().toInt32() * nExpSign;
-
-            nExp -= (sal_Int32)rInfo.nCntPre - 1;
+            sal_Int32 nRescale = (rInfo.nCntPre != 0) ? nExp % (sal_Int32)rInfo.nCntPre : -1;
+            if( nRescale < 0 && rInfo.nCntPre != 0 )
+                nRescale += (sal_Int32)rInfo.nCntPre;
+            nExp -= nRescale;
             if ( nExp < 0 )
             {
                 nExpSign = -1;
@@ -2318,6 +2314,19 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber,
                 nExpSign = 1;
             }
             ExpStr = OUString::number( nExp );
+            // rescale mantissa
+            sStr = ::rtl::math::doubleToUString( fNumber,
+                                         rtl_math_StringFormat_E,
+                                         nRescale + rInfo.nCntPost, '.' );
+            sStr.truncate( sStr.indexOf('E') );
+        }
+
+        // cut any decimal delimiter
+        sal_Int32 index = 0;
+
+        while((index = sStr.indexOf('.', index)) >= 0)
+        {
+            sStr.remove(index, 1);
         }
     }
 


More information about the Libreoffice-commits mailing list