[glom/glom-1-30] get_text_for_gda_value(): Use setprecision() on the stringstream.



commit f5e6d90860af407eb993cc7732cfa437ffbf9283
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Mar 7 17:15:33 2016 +0100

    get_text_for_gda_value(): Use setprecision() on the stringstream.
    
    To avoid losing precision when representing a GdaNumeric value as a string.
    
    And check this in test_field_file_format(), though a direct test too would
    be better.
    
    This should fix bug #763229 (m.rick.mac)

 glom/libglom/data_structure/glomconversions.cc |    3 +++
 tests/test_field_file_format.cc                |    5 ++++-
 2 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/glom/libglom/data_structure/glomconversions.cc b/glom/libglom/data_structure/glomconversions.cc
index 62455f2..7140f4a 100644
--- a/glom/libglom/data_structure/glomconversions.cc
+++ b/glom/libglom/data_structure/glomconversions.cc
@@ -498,6 +498,9 @@ Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_ty
     std::stringstream another_stream;
     another_stream.imbue(locale); //Tell it to parse stuff as per this locale.
 
+    constexpr auto precision = std::numeric_limits<decltype(number)>::maxdigits10;
+    another_stream << std::setprecision(precision);
+
     //Numeric formatting:
     if(!iso_format)
     {
diff --git a/tests/test_field_file_format.cc b/tests/test_field_file_format.cc
index f19e25a..9677398 100644
--- a/tests/test_field_file_format.cc
+++ b/tests/test_field_file_format.cc
@@ -39,7 +39,7 @@ static bool test_value(Glom::Field::glom_field_type field_type, const Gnome::Gda
 
   if(value != value_retrieved)
   {
-    std::shared_ptr<Glom::Field> field = std::make_shared<Glom::Field>();
+    std::cerr << "Unexpected: value=" << value.to_string() << ", value_retrieved=" << 
value_retrieved.to_string() << std::endl;
     std::cerr << "  value_retrieved type=" << g_type_name(value_retrieved.get_value_type()) << ", value 
type=" << g_type_name(value.get_value_type()) << std::endl;
     return false;
   }
@@ -88,6 +88,9 @@ int main()
   if(!test_value(Glom::Field::glom_field_type::NUMERIC, Glom::Conversions::parse_value((double)3.91l)))
     return EXIT_FAILURE;
 
+  if(!test_value(Glom::Field::glom_field_type::NUMERIC, Glom::Conversions::parse_value(1004914l)))
+    return EXIT_FAILURE;
+
 
   //TODO: Image.
 


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