Skip to content

Commit 46b5c90

Browse files
Fix issue with precision loss of double-type parameters in ORM inputs (#2310)
1 parent ac0d4d0 commit 46b5c90

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

orm_lib/src/SqlBinder.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <drogon/utils/Utilities.h>
1919
#include <future>
2020
#include <regex>
21+
#if defined(__cpp_lib_format)
22+
#include <format>
23+
#endif
2124
#if USE_MYSQL
2225
#include <mysql.h>
2326
#endif
@@ -259,7 +262,14 @@ SqlBinder &SqlBinder::operator<<(double f)
259262
parameters_.push_back((char *)(obj.get()));
260263
return *this;
261264
}
262-
return operator<<(std::to_string(f));
265+
266+
#if defined(__cpp_lib_format)
267+
return operator<<(std::format("{:.17g}", f));
268+
#else
269+
std::stringstream ss;
270+
ss << std::setprecision(17) << f;
271+
return operator<<(ss.str());
272+
#endif
263273
}
264274

265275
SqlBinder &SqlBinder::operator<<(std::nullptr_t)

0 commit comments

Comments
 (0)