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

QVariant doesn't properly convert floats and doubles stored within it to QString.

    XMLWordPrintable

Details

    • 8153386397087ce4f5c8997992edf5c1fd38b8db

    Description

      QVariant doesn't properly convert floats and doubles stored within it to QString.

      For example for this float stored within QVariant: 0.035003945
      After conversion to QString the string looks like: 0.0350039
      After storing string to QVariant and getting float you get: 0.035003901

      This is obviously not what is expected and unneeded and unnecessary lose of precision happens.

      The Qt implementation internally incorrectly uses: FLT_DIG and DBL_DIG which is only storing number of digits which is always representable by the number (minimum guaranteed).
      However this is not maximum guaranteed digits. For C+11 correct solution is to use std::numeric_limits<float>::max_digits10(). If you don't have C+11 support all the time, you need to specify the number manually!

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-42574
          # Subject Branch Project Status CR V

          Activity

            People

              thiago Thiago Macieira
              filousov Pavel Celba
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes