Rounding a number when the last digit is 5
-
Rounding the following
QString value= "0.3145675"; qDebug()<<"Value after rounding ="<<QString::number(value.toDouble(),'f',m_decimals); //Output - 0.314567
For such cases , the answer should be
0.314568
as per the rule Keep it EVENHow can it be achieved?
-
Rounding the following
QString value= "0.3145675"; qDebug()<<"Value after rounding ="<<QString::number(value.toDouble(),'f',m_decimals); //Output - 0.314567
For such cases , the answer should be
0.314568
as per the rule Keep it EVENHow can it be achieved?
The behavior is correct:
https://www.binaryconvert.com/result_double.html?decimal=0480460510490520530540550530.3145675
isn't exactly representable.@Swati777999 said in Rounding a number when the last digit is 5:
How can it be achieved?
By understanding how floating point numbers work and how they are represented.
https://en.wikipedia.org/wiki/Double-precision_floating-point_format