codewars / docs

The Codewars Docs :construction: WIP
https://docs.codewars.com
MIT License
55 stars 191 forks source link

Describe how to stringify double values with a requested precision. #449

Closed hobovsky closed 1 year ago

hobovsky commented 1 year ago

Present how to use custom stringizers to prevent confusing assertion messages when working with double values:

image

#include <sstream>
#include <iomanip>

namespace snowhouse {

  template<>
  struct Stringizer<double>
  {
    static std::string ToString(double value)
    {
      std::ostringstream oss;
      oss << std::setprecision(15) << value;
      return oss.str();
    }
  };
}