[glom] get_text_for_gda_value(): Use setprecision() on the stringstream.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] get_text_for_gda_value(): Use setprecision() on the stringstream.
- Date: Mon, 7 Mar 2016 16:23:56 +0000 (UTC)
commit 46690d9edb17b75f3678145d68055b2dacc64db2
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 | 4 ++++
2 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/glom/libglom/data_structure/glomconversions.cc b/glom/libglom/data_structure/glomconversions.cc
index 2d7cdbc..16b51e0 100644
--- a/glom/libglom/data_structure/glomconversions.cc
+++ b/glom/libglom/data_structure/glomconversions.cc
@@ -497,6 +497,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 8134ee7..98a7918 100644
--- a/tests/test_field_file_format.cc
+++ b/tests/test_field_file_format.cc
@@ -39,6 +39,7 @@ static bool test_value(Glom::Field::glom_field_type field_type, const Gnome::Gda
if(value != value_retrieved)
{
+ 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;
}
@@ -87,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]