I'm having trouble converting numbers to strings and retaining all of the decimal places. In the code below, both flat and flon are declared as double and have 6 decimal places (flat = 32.447134), (flon = -100.136468). After converting with QString::number, (flat = 32.4471), and (flon = -100.136). These are gps coordinates so it is very important to keep all of the decimal places.
If I shorten flon to -99.136468, it retains 4 decimal places after conversion, so it appears that there must be a limit to the length of the string of 8 characters. I need 11.
How can I convert them and retain all f the decimal places?
I have tried "QString::number(long n, int base = 10)" and others from the QT documentation but get syntax and other errors when I try to run.
Thanks in advance!
if (ui -> northeast -> isChecked())
{
flat = flat + .00007;
flon = flon + .00007;
lo = QString::number(flon);
la = QString::number(flat);
QString ll = la + "," + lo;
ui -> gps_latlon -> setText(ll);
}
You are using this overload of QString::number :
QString QString::number(double n, char format, int precision)
So pass the correct format and your required precision.
Do it like this:
str = QString::number(flat, 'f', 6);
And if you're wondering what f
means, check it out here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.