nus1998 schreef op 25-11-2014 09:33:
Hi All, I have some code like followed:
doubled=9.02;
d /= 0.02;
int i = static_cast<int>(d);
qDebug() << d << i;
the result is 451 and 450, but I want 'i' be 451 too, how?
thanks in advance
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest
This is not a Qt issue, it is a general computer issue. Familiarize
yourself with the basics of how floating point numbers work, the kinds
of inprecision that occur, and the types of rounding that are available
(round, floor, ceil). Casts are usually not the best way to deal with
converting number types. They just disgard the non integer part of a
number, even if in decimal that would be represented as .999999999999.
André
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest