QVariant precision issues

Stephen Kelly steveire at gmail.com
Tue Oct 27 22:29:44 UTC 2015


David Edmundson wrote:

> qFuzzyCompare ?

Yes, QVariant uses qFuzzyCompare internally, which means you get the 
precision that qFuzzyCompare hardcodes. You need to extract the double if 
you want to do something else.

We hit the same problem in work:

  double d1 = 1.000000000001;
  double d2 = 1.000000000002;

  QVariant v1(d1);
  QVariant v2(d2);

  qDebug()
           // False:
           << (d1 == d2)
           // True:
           << (v1 == v2)
           // False:
           << (v1.value<double>() == v2.value<double>());


Thanks,

Steve.




More information about the Kde-frameworks-devel mailing list