I can't get it why the ff code returns 12.62 instead of 12.63
QDebug << QString::number(12.625, 'f', 2);
and also what will be the solution for this? Currently my solution is this
QDebug << QString::number(12.625 + 0.0001, 'f', 2);
and it will return 12.63
.
btw my OS is ubuntu 11.04
GCC uses "Round to Even" or "Banker's Rounding" as it's default mode while Visual Studio uses "Round away from Zero"
From the GCC docs: Rounding
To change the rounding mode, use
fesetround(FE_UPWARD)
to round upwards. If you aren't using GCC, your compiler will have a similar option.Rick Regan provides a list of programming environments and their default rounding behaviours. Inconsistent Rounding