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

Conversion from QVariant to double is not consistent

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Done
    • Affects Version/s: 5.6.1
    • Fix Version/s: 5.7.0
    • Labels:
      None
    • Environment:
      Windows 7
    • Commits:
      8c2ca33073f20e1fe552bd8b5f663aec5b8a634d

      Description

      Converting a QVariant to double through "toDouble()" works differently for different values.

      Consider the following piece of code:

      QString value_1 = qs("30.45");
       QVariant variant_1(value_1);
       QString converted_value_1 = variant_1.toString();  //string value is "30.45"
       double double_value_1 = variant_1.toDouble();
       qDebug() << "Double value " << double_value_1;   
      

      ------------> Value printed is "30.4499999999"

      QString value_2 = qs("40.45");
       QVariant variant_2(value_2);
       QString converted_value_2 = variant_2.toString();   //string value is "40.45"
       double double_value_2 = variant_2.toDouble();
       qDebug() << "Double value " << double_value_2;
      

      ------------> Value printed is "40.4500000003"

      I am not sure if this conversion is platform (OS) dependent.

      I am debugging in Windows (Visual studio 13)

        Attachments

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

          Activity

            People

            Assignee:
            thiago Thiago Macieira
            Reporter:
            jagathish_baktha Jagathish Bakthavatchalam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes