
Qt → Qt/C++ - Lesson 057. Mistakes of output qDebug() for floating-point numbers
When developing software to Qt had a chance encounter with one nuance when outputting floating point numbers through qDebug() . The problem is that not all characters are displayed after the decimal point. In the same sins and output std::cout .
This user case may occur in the following situation:
You have a QString object that contains a certain number of "8564.26495574", which we translate into a floating point number using toDouble() method, and check the result with the output qDebug (), but that's bad luck, the output is false.
QString str("8564.26495574"); qDebug() << str.toDouble(); // The output is -> 8564.26
But in fact we have absolutely the right number, that is, from a string was received number 8564.26495574 just concluded qDebug() shows the rounded result.
The same can be observed if you try to bring a double number value to qDebug() .
double a = 8564.26495574; qDebug() << a; // The output is -> 8564.26
Timeweb
Let me recommend you the excellent hosting on which EVILEG is located.
For many years, Timeweb has been proving his stability.
For projects on Django I recommend VDS hosting
View Hosting