Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.9.1
-
91f3687ee51db83d9018bd61c3fbc736c6e9912e
Description
The code:
const double d = 5.0e-7; QString str1 = QString::number(d); QString str2; QTextStream ts(&str2); ts << d; QString str3; str3.sprintf("%g", d); qDebug() << str1; qDebug() << str2; qDebug() << str3; QString str4 = QString( "%1" ).arg( d ); qDebug() << str4;
produces this output:
"5e-7" "5e-07" "5e-07" "5e-7"
Obviously, QString::number produces a different string than using a text stream or sprintf. This is inconsistent.
Note, that the behavior of QString::number seems to have been changed/fixed somewhere between version 5.3 and 5.9.1, since when using version 5.3, QString::number produces a leading zero in the exponent as well.
I don't know which is the "correct" way of printing a number. However, I personally would prefer to have as few digits as possible, thus I would choose the first one (produced by QString::number).