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

develop/convert precision #774

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions modules/c++/str/include/str/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ template <typename T> int getPrecision(const types::ComplexInteger<T>&);
// Note that std::to_string() doesn't necessarily generate the same output as writing
// to std::cout; see https://en.cppreference.com/w/cpp/string/basic_string/to_string
template <typename T>
std::string toString_(const T& value)
std::string toString__(const T& value, int precision)
{
std::ostringstream buf;
buf.precision(getPrecision(value));
buf.precision(precision);
buf << std::boolalpha << value;
return buf.str();
}

template <typename T>
std::string toString_(const T& value)
{
return toString__(value, getPrecision(value));
}
template <typename T>
inline std::string toString(const T& value)
{
Expand Down
Loading