[Qt-interest] number formatting in output textstream
André Somers
andre at familiesomers.nl
Tue Oct 6 08:54:34 CEST 2009
[Qt 4.5.2 on Windows XP-64]
Hi,
I am trying to output data to a textfile. The file contains both integers
and floating point numbers. Due to the program reading in the data, I have
specific requirements to the formatting of these numbers. Specifically, I
need the integers be formatted without anything added (just the number, no
thousands separators) but the floats formatted as defined in the locale
(here usually a comma is used for the decimals).
I tried the following approach:
QTextStream s(&file); // file is a QFile, opened in writing mode
QLocale l = QLocale::system(); //get system locale
l.setNumberOptions(QLocale::OmitGroupSeparator); // I dont want to use
separators, but are group-separators the same as thousands-separators?
s.setLocale(l);
s << integer1 << << integer2 << << float1 << endl; // output a line
of data
This does not work as expected. I had hoped the OmitGroupSeparator flag
would stop the outputting of thousandsseparators, but I still get them when
the integers are bigger than 1000. Am I overlooking something? Is there a
way to get around this?
If I dont set the locale explicitly, I dont get the thousands separators,
but then I end up with a point as the decimal separator. That doesnt work
for me, as the target application (which I can not change) *does* use the
locale for the formatting of floating point numbers. QLocale only seems to
support reading the characters used for the separators, but not setting
them.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091006/0673548d/attachment.html
More information about the Qt-interest-old
mailing list