Thanks, wysota.
I noticed that your example uses only 4 decimals, indeed, more than was shown in my post but not enough for my actual app. In several cases there are *1000 and /1000 operators between doubles and QString.setNum.
That did get me thinking...a little more experimentation revealed a combination of my error and the default behavior of qDebug.
setNum() without parameters #2 and #3 defaults to 'g', 6.
Scott assumed the default '6' was decimals. Yes, format 'f' is 6 decimals, format 'g' is 6 total digits.
Qt apparently uses that default ('g', 6) when executing double conversions in qDebug. That's logical, I suppose.
Here's part of the test and results...
// expanded testing inside the app
ui->SpinBox->setValue(7777.777);
sz1 = "7777.777";
dbl1 = sz1.toDouble();
dbl2 = ui->SpinBox->value();
sz2.setNum(dbl1);
sz3.setNum(dbl2);
sz4.setNum(dbl1, 'g', 6);
sz5.setNum(dbl1, 'g', 8);
qDebug() << dbl1 << dbl2 << sz1 << sz2 << sz3 << sz4 << sz5;
// qDebug output:
// 7777.78 7777.78 "7777.777" "7777.78" "7777.78" "7777.78" "7777.777"
// expanded testing inside the app
ui->SpinBox->setValue(7777.777);
sz1 = "7777.777";
dbl1 = sz1.toDouble();
dbl2 = ui->SpinBox->value();
sz2.setNum(dbl1);
sz3.setNum(dbl2);
sz4.setNum(dbl1, 'g', 6);
sz5.setNum(dbl1, 'g', 8);
qDebug() << dbl1 << dbl2 << sz1 << sz2 << sz3 << sz4 << sz5;
// qDebug output:
// 7777.78 7777.78 "7777.777" "7777.78" "7777.78" "7777.78" "7777.777"
To copy to clipboard, switch view to plain text mode
Now try to "break" your example. ( Um...uh...but it's a really gooood example !! )
// added
setSingleStep(33.0001); // large steps, and make decimals visible
setMaximum(10000000); // default is 100
// qDebug output - note the disappearing decimal digits
// direct: 99.0003
// transformed: 99000.3
// direct: 132
// transformed: 132000
// direct: 165.001
// transformed: 165001
// added
setSingleStep(33.0001); // large steps, and make decimals visible
setMaximum(10000000); // default is 100
// qDebug output - note the disappearing decimal digits
// direct: 99.0003
// transformed: 99000.3
// direct: 132
// transformed: 132000
// direct: 165.001
// transformed: 165001
To copy to clipboard, switch view to plain text mode
I'll be a little wary of qDebug. Of course it needs to run as fast as possible and there are tradeoffs in there.
Hope this helps someone else.
Cheers,
Scott
Bookmarks