From fae29d081af4998823571e0ecc6d4e0c5b8d52eb Mon Sep 17 00:00:00 2001 From: Victor Lyuboslavsky Date: Mon, 10 Jun 2024 11:07:52 -0500 Subject: [PATCH] Using `std::setprecision` to get the right precision for double to string conversion. (#8302) --- osquery/utils/conversions/castvariant.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osquery/utils/conversions/castvariant.h b/osquery/utils/conversions/castvariant.h index b4da4882790..319d3c6702a 100644 --- a/osquery/utils/conversions/castvariant.h +++ b/osquery/utils/conversions/castvariant.h @@ -9,7 +9,11 @@ #pragma once -#include +#include +#include +#include +#include +#include #include namespace osquery { @@ -23,7 +27,9 @@ class CastVisitor : public boost::static_visitor { } std::string operator()(const double& d) const { - std::string s{boost::lexical_cast(d)}; + std::ostringstream ss; + ss << std::setprecision(std::numeric_limits::digits10 + 1) << d; + std::string s = ss.str(); if (s.find('.') == std::string::npos) { s += ".0"; }