-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query Execution
Currently, converting doubles to strings produces strings no longer than 6 characters, and drops anything after the decimal place that would require going above 6 characters. At 6 decimal places it automatically converts to scientific notation. This is an issue resulting from
ostream <<
which can be seen here:
https://repl.it/repls/DefensiveCoarseMedia
The easiest way to improve this is to change the operator << definition for bson docs here:
https://github.com/mongodb/mongo/blob/b89f752fe24dd4b24d59f39ea2f45b01aaca8250/src/mongo/db/pipeline/value.cpp#L1115
Since this appears to be a problem even using std::setprecision (it sets the number of characters in the string instead of the actual precision), I would suggest using std::sprintf and std::snprintf like the following:
auto input = 500000000000000.1; auto size = std::snprintf(NULL, 0, "%.10f", input); auto buff = static_cast<char *>(alloca(sizeof(char) * size)); std::sprintf(buff, "%.10f", input); out << buff;
If we decide we want to use 10 decimal places.