PDA

View Full Version : Help with QString.toDouble()



manolaris
4th July 2008, 16:57
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

wysota
4th July 2008, 18:05
What is the type of "lat"?

manolaris
5th July 2008, 17:27
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