[Solved] Precision of qDebug()?
-
Hi,
I have a double variable (say x) with a value like 0.123456789e-10. When I print the value of x via qDebug(), it is showing only part of the value.
qDebug() << x << endl;
So, this prints 0.1234e-10. I want it to print 0.123456789e-10. How can I do that?
Similarly if x = 0.0000012345. It prints 1.234e-6, but I want it to print 0.0000012345. How can I do that?
I have installed a messagehandler so that the output from qDebug() is printed to a file.
Thank You. -
Yes but isn't that a bit tedious to, convert a double to a string every time I have to just print its value with better precision?
-
Try something like this:
@
qDebug() << qSetRealNumberPrecision( 10 ) << "x = " << x;
@There are a whole bunch of ways to configure the QTextStream object used by qDebug(). See for example http://qt-project.org/doc/qt-5.0/qtcore/qtextstream.html#qSetRealNumberPrecision and http://qt-project.org/doc/qt-5.0/qtcore/qtextstream.html#qtextstream-manipulators
-
Hi ZapB,
Thanks for that!
I will try that & let you know if there is any problem.@chris17, I will keep that in mind for my next project. Thanks.
UPDATE: Hi ZapB,
Since I have used my messagehandler for qDebug() to print to a file, is it possible to do something so that the text stream for my messagehandler can be set with the realnumberprecision property only once at startup so that I dont have to add the code you showed every time I am using qDebug()?