I have the following code that I am trying to add a double number to a QLabel that must have the following format MMM.NN , this a number less than 100.0 should have a leading 0
double _Heading = 35.5;
_Stream.
setRealNumberNotation(QTextStream::FixedNotation);
_Stream.setRealNumberPrecision(2);
_Stream.setPadChar('0');
_Stream <<
"HDG: " <<
QTextStream::ForcePoint << _Heading;
QString _qs
= *(lcStream.
string());
std::cout << "_Stream: " << _qs.toUtf8().constData() << std::endl;
double _Heading = 35.5;
QString _TextForDisplay;
QTextStream _Stream(&_TextForDisplay);
_Stream.setRealNumberNotation(QTextStream::FixedNotation);
_Stream.setRealNumberPrecision(2);
_Stream.setFieldAlignment(QTextStream::AlignRight);
_Stream.setPadChar('0');
_Stream << "HDG: " << QTextStream::ForcePoint << _Heading;
QString _qs = *(lcStream.string());
std::cout << "_Stream: " << _qs.toUtf8().constData() << std::endl;
To copy to clipboard, switch view to plain text mode
But I get
"_Stream : 235.50" not "035.50".
??? Where is the leading "2" coming from???
>>
Note that using std:stringstream produces the expected results:
std::ostringstream _TextStream;
_TextStream << "HDG: " << std::dec << std::fixed << std::setprecision(2) << _Heading;
std::cout << lcTextStream.str() << std::endl;
std::ostringstream _TextStream;
_TextStream << "HDG: " << std::dec << std::fixed << std::setprecision(2) << _Heading;
std::cout << lcTextStream.str() << std::endl;
To copy to clipboard, switch view to plain text mode
"035.50"
Thanks.
Bookmarks