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

QVariant::toString() has a different output between 5/6 on floating point (double) numbers

    XMLWordPrintable

Details

    Description

      This program:

      #include <QVariant>
      #include <QDebug>
      
      int main()
      {
          double d = 200000;
          QVariant v = d;
          qDebug() << v;
          qDebug() << v.toString();
          qDebug() << QString::number(d, 'e');
          qDebug() << QString::number(d, 'f');
          qDebug() << QString::number(d, 'g');
          qDebug() << QString::number(d, 'g', 128);
          qDebug() << QString::number(d, 'g', -128);
      }
      

      Has different outputs between Qt 5 and 6.

      On Qt 5:

      QVariant(double, 200000)
      "200000"
      "2.000000e+05"
      "200000.000000"
      "200000"
      "200000"
      "200000"
      

      And on Qt 6:

      QVariant(double, 200000)
      "2e+05"
      "2.000000e+05"
      "200000.000000"
      "200000"
      "200000"
      "2e+05"
      

      I'm not sure whether such a change was deliberate.

      Attachments

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

        Activity

          People

            Eddy Edward Welbourne
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes