Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52410

add a property to QJsonDocument for double precision

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • Not Evaluated
    • 5.7.0
    • None
    • Core: Other
    • 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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            laknoll Lars Knoll
            evilruff Yuri Alexandrov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes