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

QVariant converts floats to string with too much decimal digits

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.10.1
    • None
    • All

    Description

      The QVariant in which a float is stored is able to produce its string representation with too much decimal digits with the method toString().

      Consider following float: -10795.0684
      The following string is generated: -10795.068359375
      While this is in fact correct, it's unnecessary information and it causes e.g. Validator on float expecting just 7 decimal digits to fail.

      The bug is on the qvariant.cpp - line 433 which sends the float into the QString conversion method: *str = QString::number(d->data.f, 'g', QLocale::FloatingPointShortest);
      With double decimal digits requested. The float is converted here to double and hence it gains additional precision!

      Instead std::numeric_limits<float>::digits should be used there.

       

      Attachments

        Issue Links

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

          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