cpptoml
cpptoml copied to clipboard
ability to specify double precision when writing out
Would love to have the ability to specify the precision/digits to use when writing out floats. Currently cpptoml
is writing out numbers like 0.29799999999999999 and 0.60999999999999999 which contain way too much precision for the source #s (0.298 and 0.610) and simply being able to tell cpptoml
to round all doubles to X digits would not only fix that but make these much friendlier and more accurate numbers for human readers/editors of the config.
Inspired by this we've done the following in my visitor
function, to output double values in a better way:
void visit(const cpptoml::value<double>& v) {
// Don't use default precision of stringstream
std::stringstream ss;
ss << std::showpoint << std::setprecision(std::numeric_limits<double>::max_digits10 - 1) << v.get();
m_stream << ss.str();
}
...
...
std::ostringstream m_stream;