PDA

View Full Version : Print floating and double precision number



marc2050
17th May 2011, 07:45
Hi.

I've a number y = 0.62354642

When I try
QString("%1").arg(y)

It does not show on my screen the full 0.62354642.
Rather is shows the value of '1'.
My variables are declared as float. And I've been able to output variables values on my screen. But it is the first time I'm trying to see the values in float precision.
How do I see the results up to the exact decimal places?

Thanks.

cincirin
17th May 2011, 07:59
You can simply use setNum (http://doc.qt.nokia.com/latest/qstring.html#setNum-10)

ChrisW67
17th May 2011, 08:15
I've a number y = 0.62354642

When I try
QString("%1").arg(y)

It does not show on my screen the full 0.62354642.
Rather is shows the value of '1'.

Then the value y is 1 (or within a small margin of it) not 0.62354642. Have you done an integer operation/assignment somewhere? Or have just left out the percent sign in the QString template?



double y1 = 0.62354642;
float y2 = 0.62354642;
qDebug() << QString("%1").arg(y1) << QString::number(y1, 'g', 8) ;
qDebug() << QString("%1").arg(y2) << QString::number(y2, 'g', 8) ;

outputs:


"0.623546" "0.62354642"
"0.623546" "0.62354642"