[mapguide-commits] r9229 - in sandbox/jng/geoprocessing: Common/Foundation/System Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jun 28 08:18:59 PDT 2017


Author: jng
Date: 2017-06-28 08:18:59 -0700 (Wed, 28 Jun 2017)
New Revision: 9229

Modified:
   sandbox/jng/geoprocessing/Common/Foundation/System/Util.cpp
   sandbox/jng/geoprocessing/Server/src/UnitTesting/TestMisc.cpp
Log:
Refine MgUtil::DoubleToString

Modified: sandbox/jng/geoprocessing/Common/Foundation/System/Util.cpp
===================================================================
--- sandbox/jng/geoprocessing/Common/Foundation/System/Util.cpp	2017-06-28 13:50:07 UTC (rev 9228)
+++ sandbox/jng/geoprocessing/Common/Foundation/System/Util.cpp	2017-06-28 15:18:59 UTC (rev 9229)
@@ -1092,8 +1092,11 @@
     else
     {
         std::stringstream ss;
-        ss << std::setprecision(decimals + 1) << val;
+        ss << std::fixed << std::setprecision(decimals) << val;
         str = ss.str();
+        // Slice off trailing 0s
+        size_t end = str.find_last_not_of('0') + 1;
+        str.erase(end);
     }
 }
 
@@ -1106,8 +1109,11 @@
     else
     {
         std::wstringstream ws;
-        ws << std::setprecision(decimals + 1) << val;
+        ws << std::fixed << std::setprecision(decimals) << val;
         str = ws.str();
+        // Slice off trailing 0s
+        size_t end = str.find_last_not_of(L'0') + 1;
+        str.erase(end);
     }
 }
 

Modified: sandbox/jng/geoprocessing/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- sandbox/jng/geoprocessing/Server/src/UnitTesting/TestMisc.cpp	2017-06-28 13:50:07 UTC (rev 9228)
+++ sandbox/jng/geoprocessing/Server/src/UnitTesting/TestMisc.cpp	2017-06-28 15:18:59 UTC (rev 9229)
@@ -693,6 +693,17 @@
 
         CPPUNIT_ASSERT(L"1.1" == ws);
         CPPUNIT_ASSERT("1.1" == s);
+
+        double d2 = 123.3457483434945;
+
+        ws.clear();
+        s.clear();
+
+        MgUtil::DoubleToString(d2, ws, 8);
+        MgUtil::DoubleToString(d2, s, 8);
+
+        CPPUNIT_ASSERT(L"123.34574834" == ws);
+        CPPUNIT_ASSERT("123.34574834" == s);
     }
     catch (MgException* e)
     {



More information about the mapguide-commits mailing list