Double values suffer from machine precision. That means that 4.6 does not necessarily have to be exactly equal to 4.6. You should use another approach using qFuzzyCompare(), that takes into account this issue. Maybe you can write a template specialization for it, but that would mean you have that behavior throughout your program, and requires you to do template magic.

Qt Code:
  1. bool SomeClass::listContains(qreal value) const
  2. {
  3. foreach (qreal v, theList) {
  4. if (qFuzzyCompare(value, v))
  5. return true;
  6. }
  7. return false;
  8. }
To copy to clipboard, switch view to plain text mode