Skip to content

Commit

Permalink
Using std::setprecision to get the right precision for double to st…
Browse files Browse the repository at this point in the history
…ring conversion. (osquery#8302)
  • Loading branch information
getvictor authored Jun 10, 2024
1 parent e712bef commit fae29d0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions osquery/utils/conversions/castvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

#pragma once

#include <boost/lexical_cast.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant.hpp>
#include <iomanip>
#include <sstream>
#include <string>

namespace osquery {
Expand All @@ -23,7 +27,9 @@ class CastVisitor : public boost::static_visitor<std::string> {
}

std::string operator()(const double& d) const {
std::string s{boost::lexical_cast<std::string>(d)};
std::ostringstream ss;
ss << std::setprecision(std::numeric_limits<double>::digits10 + 1) << d;
std::string s = ss.str();
if (s.find('.') == std::string::npos) {
s += ".0";
}
Expand Down

0 comments on commit fae29d0

Please sign in to comment.