Variable Problem
-
wrote on 1 Apr 2013, 22:35 last edited by
Hello guys.
I have a little problem. My program reads numbers from txt file and show.
data.txt
@12345,67e-09@code.cpp
@
...
QFile file(fileName);
QTextStream in(&file);double textData;
QString data;in >> data;
textData = data.toDouble();
@It works. But when i change data.txt, there is a problem.
data.txt
@1234567e-09@Program shows the number that is 0,00123457. I want to show 1234567 x 10^9 ( = 1234567 x 1000000000 ).
I guess The problem occur because of double variable type. How can i fix this?
-
wrote on 2 Apr 2013, 00:11 last edited by
[quote author="kingsta" date="1364855711"]@1234567e-09@
Program shows the number that is 0,00123457. I want to show 1234567 x 10^9 ( = 1234567 x 1000000000 ).[/quote]
Why?
If the file contains "1234567e-09", which according to the "scientific notation":http://en.wikipedia.org/wiki/Scientific_notation means "1234567 × 10^(-9)" and not "1234567 × 10^9". The latter would be "1234567e09" instead of "1234567e-09".
But if you want the text to be interpreted differently from the "usual" commonly-accepted conventions, you will have to read it as QString and then implement your own "non-standard" parser logic...
--
BTW: As plain text always is ambiguous (unless both sides agree an a strict convention), you should better use a QDataStream. This class provides well-defined and platform-independent encodings for all common data types.
-
wrote on 2 Apr 2013, 11:42 last edited by
[quote author="MuldeR" date="1364861518"][quote author="kingsta" date="1364855711"]@1234567e-09@
Program shows the number that is 0,00123457. I want to show 1234567 x 10^9 ( = 1234567 x 1000000000 ).[/quote]
Why?
If the file contains "1234567e-09", which according to the "scientific notation":http://en.wikipedia.org/wiki/Scientific_notation means "1234567 × 10^(-9)" and not "1234567 × 10^9". The latter would be "1234567e09" instead of "1234567e-09".
But if you want the text to be interpreted differently from the "usual" commonly-accepted conventions, you will have to read it as QString and then implement your own "non-standard" parser logic...
--
BTW: As plain text always is ambiguous (unless both sides agree an a strict convention), you should better use a QDataStream. This class provides well-defined and platform-independent encodings for all common data types.[/quote]
Thanks for help. Yes you right I was wrong. I am going to look QDataStream.
1/3