From 5f2925c59cb3b6fa580e565e2d5a4dad3c400eeb Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Thu, 12 Jan 2023 14:12:31 -0500 Subject: Increase `ftos` precision (#13141) --- src/util/string.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 2f3c2615b..27e2f094d 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include #include #include #include @@ -429,14 +430,11 @@ inline std::string itos(s32 i) { return std::to_string(i); } /// Returns a string representing the decimal value of the 64-bit value \p i. inline std::string i64tos(s64 i) { return std::to_string(i); } -// std::to_string uses the '%.6f' conversion, which is inconsistent with -// std::ostream::operator<<() and impractical too. ftos() uses the -// more generic and std::ostream::operator<<()-compatible '%G' format. -/// Returns a string representing the decimal value of the float value \p f. +/// Returns a string representing the exact decimal value of the float value \p f. inline std::string ftos(float f) { std::ostringstream oss; - oss << f; + oss << std::setprecision(std::numeric_limits::max_digits10) << f; return oss.str(); } -- cgit v1.2.3