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

[REG 5.6->5.7]: Inconsistency with leading zero for double-to-string conversions with a single digit exponent

    XMLWordPrintable

Details

    • 91f3687ee51db83d9018bd61c3fbc736c6e9912e

    Description

      The code:

      const double d = 5.0e-7;
      QString str1 = QString::number(d);
      QString str2;
      QTextStream ts(&str2);
      ts << d;
      QString str3;
      str3.sprintf("%g", d);
      qDebug() << str1;
      qDebug() << str2;
      qDebug() << str3;
      QString str4 = QString( "%1" ).arg( d );
      qDebug() << str4;

      produces this output:

      "5e-7"
      "5e-07"
      "5e-07"
      "5e-7"
      

      Obviously, QString::number produces a different string than using a text stream or sprintf. This is inconsistent.

      Note, that the behavior of QString::number seems to have been changed/fixed somewhere between version 5.3 and 5.9.1, since when using version 5.3, QString::number produces a leading zero in the exponent as well.

      I don't know which is the "correct" way of printing a number. However, I personally would prefer to have as few digits as possible, thus I would choose the first one (produced by QString::number).

      Attachments

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

        Activity

          People

            Eddy Edward Welbourne
            boernsen boernsen
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes