Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to specify double precision when writing out #99

Open
nephatrine opened this issue Feb 7, 2019 · 1 comment
Open

ability to specify double precision when writing out #99

nephatrine opened this issue Feb 7, 2019 · 1 comment

Comments

@nephatrine
Copy link
Contributor

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.

@pkbehera
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants