PDA

View Full Version : how to set double precision



saman_artorious
27th February 2013, 09:27
My double is 00.0 format. when I set it to QLCDNumber .display(double)
it automatically removes the precisions and displays 0

02.0 -> as 2.0
0.0 -> 0
20.0 -> 20
and so on. How can I force it keep it's format?

Added after 9 minutes:


My double is 00.0 format. when I set it to QLCDNumber .display(double)
it automatically removes the precisions and displays 0

02.0 -> as 2.0
0.0 -> 0
20.0 -> 20
and so on. How can I force it keep it's format?

I did this:
QString str = QString::number(f, 'f', 1);

now, how can I padleft the float? so that when I enter 02.0 it shows it and not 2.0? does qt support it?

Lesiok
27th February 2013, 09:37
Read about QString::rightJustified. And for the future: read the documentation, it does not hurt.

saman_artorious
27th February 2013, 10:17
Read about QString::rightJustified. And for the future: read the documentation, it does not hurt.

result is not as expected. had to do this to get the expected result:


QString str = QString::number(f, 'f', 1);
if(str.length() == 3)
str.insert(0, '0');

wysota
27th February 2013, 11:17
QString(%1).arg(f, 5, 'f', 1, '0');

or similar. RightJustified() would also work.

ChrisW67
28th February 2013, 00:48
it automatically removes the precisions and displays 0
02.0 -> as 2.0

A leading zero has nothing to do with precision.