glom r1903 - in branches/glom-1-8: . glom/libglom/data_structure



Author: murrayc
Date: Mon Feb 16 21:23:08 2009
New Revision: 1903
URL: http://svn.gnome.org/viewvc/glom?rev=1903&view=rev

Log:
2009-02-16  Murray Cumming  <murrayc murrayc com>

* glom/libglom/data_structure/glomconversions.cc:
get_text_for_gda_value(), parse_value(): Use std::setprecision() to 
avoid showing the awkward scientific e notation, raising the limit 
from 7 digits to 15. We don't know how to avoid it always.
Noticed by Arq. Maximiliano MeilÃn.

Modified:
   branches/glom-1-8/ChangeLog
   branches/glom-1-8/glom/libglom/data_structure/glomconversions.cc

Modified: branches/glom-1-8/glom/libglom/data_structure/glomconversions.cc
==============================================================================
--- branches/glom-1-8/glom/libglom/data_structure/glomconversions.cc	(original)
+++ branches/glom-1-8/glom/libglom/data_structure/glomconversions.cc	Mon Feb 16 21:23:08 2009
@@ -38,6 +38,10 @@
 namespace Glom
 {
 
+// Increase the number of digits (even before the decimal point) we can 
+// have until it uses the awkward e syntax. The default seems to be 7
+static const int STRINGSTREAM_PRECISION_DEFAULT = 15;
+
 Glib::ustring Conversions::format_time(const tm& tm_data)
 {
   return format_time( tm_data, std::locale("") /* the user's current locale */ ); //Get the current locale.
@@ -356,7 +360,15 @@
       if(numeric_format.m_decimal_places_restricted)
       {
         another_stream << std::fixed;
-        another_stream << std::setprecision(numeric_format.m_decimal_places); //precision means number of decimal places when using std::fixed.
+
+        //precision means number of decimal places when using std::fixed:
+        another_stream << std::setprecision(numeric_format.m_decimal_places);
+      }
+      else
+      {
+        //Increase the number of digits (even before the decimal point) we can 
+        //have until it uses the awkward e syntax. The default seems to be 7.
+        another_stream << std::setprecision(STRINGSTREAM_PRECISION_DEFAULT);
       }
 
       if(!(numeric_format.m_currency_symbol.empty()))
@@ -415,6 +427,7 @@
   std::stringstream clocale_stream;
   clocale_stream.imbue( std::locale::classic() ); //The C locale.
   clocale_stream << number;
+  clocale_stream << std::setprecision(STRINGSTREAM_PRECISION_DEFAULT); //Avoid the e syntax. Normally this happens afer 7 digits, with loss of precision. TODO: Handle more.
   Glib::ustring number_canonical_text = clocale_stream.str(); //Avoid << because it does implicit character conversion (though that might not be a problem here. Not sure). murrayc
 
   //TODO: What about the precision and width values?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]