Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Variable Problem
QtWS25 Last Chance

Variable Problem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kingsta
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      [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.

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kingsta
        wrote on last edited by
        #3

        [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 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved