The closest approximation of 2582.3250 as a float is 2582.324951171875. Perhaps it is obvious now why it rounds the way it does.
Have a play with this here
You are also assuming there is only one way to round: that is 0.5 rounds up. The IEEE754 default rounding method is round-to-even so 1.125 rounds to 1.12, and 1.375 rounds to 1.38, and that is what Qt does also:
qDebug
() <<
QString::number(1.125,
'f',
2);
// outputs "1.12"qDebug
() <<
QString::number(1.375,
'f',
2);
// outputs "1.38"
qDebug() << QString::number(1.125, 'f', 2); // outputs "1.12"
qDebug() << QString::number(1.375, 'f', 2); // outputs "1.38"
To copy to clipboard, switch view to plain text mode
(Both those numbers have an exact floating point representation)
Bookmarks