Results 1 to 3 of 3

Thread: Help with QString.toDouble()

  1. #1

    Default Help with QString.toDouble()

    Hi,

    i am programming a small application which takes a NMEA sentence (those used by GPS, sounds, and maritime instruments) and writes into a file several parameters.

    I take the senteces from a text file with the usual QFile+QTextStream procedure and I read each one with .readLine() into a QString, then I split the QString into a QStringList.

    My problem comes when I try to do some maths. In the case of latitude values, they come out from my NMEA file like:

    3621.234
    3621.236
    3621.236
    3621.236

    and I have to divide it by 100 to get the correct position (36.21236 degrees for instance)

    But when I do (assuming linea as a QStringList and being lat a double)

    lat=(linea.at(3).toDouble());
    lat=lat/100.000000;

    What I get are truncated or rounded values (I lost one decimal cipher):

    36.2123
    36.2123
    36.2123
    36.2123

    I've tried different things but I haven't obtained results yet.

    Could you help me a bit, please?

    Cheers

    Jorge Tornero

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with QString.toDouble()

    What is the type of "lat"?

  3. #3

    Default Re: Help with QString.toDouble() [Apparently SOLVED]

    Hi,

    it seems enough to use QTextStream::setRealNumberPrecision() to the desired number of decimals.

    Thank you very much to all for your help anyway.

    Cheers

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.