Details
-
Suggestion
-
Resolution: Done
-
Not Evaluated
-
None
-
None
-
573f87d81363a303b7005f999a283db624201db8
Description
Hi,
As I can see in the current source then formatting double values to JSON text there is a following code:
QJsonWriter.cpp
case QJsonValue::Double: { const double d = v.toDouble(b); if (qIsFinite(d)) // +2 to format to ensure the expected precision json += QByteArray::number(d, 'g', std::numeric_limits<double>::digits10 + 2); // ::digits10 is 15 else json += "null"; // +INF || -INF || NaN (see RFC4627#section2.4) break; }
However there are many cases then server side expects a doubles with specified precision (most known example is Bitcoind RPC which expects 8 digits), with a current implementation its an absolute pain to implement JSON formatting with custom precision options.
I propose to add a setting in the formatter via QJsonDocument, how Doubles should be converted into the strings.
it can be done just by adding a parameter to 'toJson' function or by adding a new setting to QJsonDocument and use it in toJson call