From 0e076bf47c6cd3ba7f099859062cf188de712dbd Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 2 Jan 2022 10:32:52 +0100 Subject: [PATCH] Dump floating point numbers in info string with as little decimal places as possible --- .../InfoStringFromStructConverterBase.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ObjWriting/InfoString/InfoStringFromStructConverterBase.cpp b/src/ObjWriting/InfoString/InfoStringFromStructConverterBase.cpp index 4c394f17..c06adaf9 100644 --- a/src/ObjWriting/InfoString/InfoStringFromStructConverterBase.cpp +++ b/src/ObjWriting/InfoString/InfoStringFromStructConverterBase.cpp @@ -2,6 +2,7 @@ #include #include +#include InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure) : m_structure(structure), @@ -78,13 +79,23 @@ void InfoStringFromStructConverterBase::FillFromQBoolean(const std::string& key, void InfoStringFromStructConverterBase::FillFromFloat(const std::string& key, const size_t offset) { const auto* num = reinterpret_cast(reinterpret_cast(m_structure) + offset); - m_info_string.SetValueForKey(key, std::to_string(*num)); + + std::ostringstream ss; + ss << *num; + + m_info_string.SetValueForKey(key, ss.str()); } void InfoStringFromStructConverterBase::FillFromMilliseconds(const std::string& key, const size_t offset) { const auto* millis = reinterpret_cast(reinterpret_cast(m_structure) + offset); - m_info_string.SetValueForKey(key, std::to_string(static_cast(*millis) / 1000.0f)); + + const auto value = static_cast(*millis) / 1000.0f; + + std::ostringstream ss; + ss << value; + + m_info_string.SetValueForKey(key, ss.str()); } void InfoStringFromStructConverterBase::FillFromScriptString(const std::string& key, const size_t offset)