Hello,

We have noticed anomalies in our applications accounting procedures where sale, cost prices are counted and etc. We are using Qt 4.3.5 on Windows.

Problem looks like is in QDoubleSpinBox double rounding. Please take a look:

Qt Code:
  1. #include <QApplication>
  2. #include <QDebug>
  3. #include <QDoubleSpinBox>
  4. #include <QWidget>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication a(argc, argv);
  9.  
  10.  
  11. QDoubleSpinBox doubleBox(&w);
  12. doubleBox.setDecimals(4);
  13.  
  14. doubleBox.setValue(2.79825);
  15. qDebug() << QString::number(doubleBox.value(),'g');
  16.  
  17. doubleBox.setValue(2.79835);
  18. qDebug() << QString::number(doubleBox.value(),'g');
  19.  
  20. w.show();
  21.  
  22. return a.exec();
  23. }
To copy to clipboard, switch view to plain text mode 

You can notice that 2.79825 becomes 2.7982, and 2.79835 goes to, as I believe it really should, 2.7984.

I have no idea what kind of "double magic" is going on. Can it be Qt bug or "natural" double rounding behavior? You also can find similar strange behavior with 2.55, 2.555, 2.5555, 2.55555 and etc. with respectively 1, 2, 3, etc. decimal places - not always you will get "..6" at the end.

Thank you.