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

QString::arg(double) inconsistent rounding

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.1.0
    • None
    • Mac OS X 10.7 and Windows

    Description

      Hello,

      QString::arg() uses number flooring and ceiling inconsistently.

      Have a look at the following table where the
      1st column is the double used as argument of the arg() method
      2nd column, the result of QString("%1").arg(myDouble, 0, 'G', 3);

      qDebug() << QString("%1").arg(myDouble, 0, 'e', 20) << QString("%1").arg(myDouble, 0, 'G', 3);

      "1.08500000000000000000e+02" "108"
      "1.09500000000000000000e+02" "110"
      "1.10500000000000000000e+02" "110"
      "1.11500000000000000000e+02" "112"
      "1.12500000000000000000e+02" "112"
      "1.13500000000000000000e+02" "114"

      The 2nd column is not rounded consistently:
      108.5 is presented as 108 expected 109 KO
      109.5 is presented as 110 expected 110 OK

      Same exercise with arg(myDouble, 0, 'G', -1):

      qDebug() << QString("%1").arg(myDouble, 0, 'e', 20) << QString("%1").arg(myDouble, 0, 'G', -1);
      "1.11108500000000000000e+05" "111108"
      "1.11109500000000000000e+05" "111110"
      "1.11110500000000000000e+05" "111110"
      "1.11111500000000000000e+05" "111112"
      "1.11112500000000000000e+05" "111112"
      "1.11113500000000000000e+05" "111114"

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            vince Vince
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes