File prettytostring.h
File List > code_source > templat > include > TempLat > util > prettytostring.h
Go to the documentation of this file
#ifndef TEMPLAT_UTIL_PRETTYTOSTRING_H
#define TEMPLAT_UTIL_PRETTYTOSTRING_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Adrien Florio, Year: 2020
#include <sstream>
#include <string>
namespace TempLat
{
class PrettyToString
{
public:
// Put public methods here. These should change very little over time.
PrettyToString() = default;
template <typename R> static std::string get(R x, int prec = 14)
{
std::ostringstream out;
out.precision(prec);
out << std::fixed << x;
std::string res(out.str());
removeZeros(res);
return res;
}
private:
/* Put all member variables and private methods here. These may change arbitrarily. */
static void removeZeros(std::string &x)
{
while (x.back() == '0')
x.pop_back();
}
};
} // namespace TempLat
#endif