From 2bd5883ac0b2f06a93a2caf297446f930153f7d9 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Sat, 5 Oct 2024 11:07:52 +0200 Subject: [PATCH] TableHandler::set_scientific(): fix int --- doc/news/changes/minor/20241005Munch | 4 ++++ source/base/table_handler.cc | 5 ++++- tests/base/table_handler_10.cc | 8 ++++---- tests/base/table_handler_10.output | 8 ++++---- 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 doc/news/changes/minor/20241005Munch diff --git a/doc/news/changes/minor/20241005Munch b/doc/news/changes/minor/20241005Munch new file mode 100644 index 0000000000..0b1719fa6d --- /dev/null +++ b/doc/news/changes/minor/20241005Munch @@ -0,0 +1,4 @@ +Improved: TableHandler now correctly outputs Integers if +TableHandler::set_scientific() is set. +
+(Peter Munch, 2024/10/05) diff --git a/source/base/table_handler.cc b/source/base/table_handler.cc index bb32bbc9ff..5ce1351085 100644 --- a/source/base/table_handler.cc +++ b/source/base/table_handler.cc @@ -90,7 +90,10 @@ namespace internal else ss.setf(std::ios::fixed, std::ios::floatfield); - std::visit([&ss](const auto &v) { ss << v; }, value); + if (scientific) + ss << get_numeric_value(); + else + std::visit([&ss](const auto &v) { ss << v; }, value); cached_value = ss.str(); if (cached_value.empty()) diff --git a/tests/base/table_handler_10.cc b/tests/base/table_handler_10.cc index a4a84a2138..0c5fd2c358 100644 --- a/tests/base/table_handler_10.cc +++ b/tests/base/table_handler_10.cc @@ -36,15 +36,15 @@ main() std::string keys[3] = {"key1", "key2", "key3"}; // fill rows 1 and 2 partially - table.add_value(keys[0], 0.0); - table.add_value(keys[0], 1.0); + table.add_value(keys[0], 0); + table.add_value(keys[0], 1); // now fill row 3 completely - table.add_value(keys[0], 2.0); + table.add_value(keys[0], 2); table.add_value(keys[1], 123.456); table.add_value(keys[2], std::string("abc")); // now again fill row 4 partially - table.add_value(keys[0], 1.0); + table.add_value(keys[0], 1); // produce output. hope that row 4 is // completely padded diff --git a/tests/base/table_handler_10.output b/tests/base/table_handler_10.output index e4cc24e56d..165540898d 100644 --- a/tests/base/table_handler_10.output +++ b/tests/base/table_handler_10.output @@ -2,10 +2,10 @@ # 1: key1 # 2: key2 # 3: key3 -0.0000 0.0000 "" -1.0000 0.0000 "" -2.0000 123.4560 abc -1.0000 0.0000 "" +0 0.0000 "" +1 0.0000 "" +2 123.4560 abc +1 0.0000 "" # 1: key1 # 2: key2 # 3: key3 -- 2.39.5