I am using Qt and want to print a data value (double) in a label; however, the trailing zeros are lopped off. I know in C I can use printf("%0.1f", data) to preserve the trailing zeros.
I looked at QString's arg function but that only allows the overall field width to be set. setNum and number each allow the precision to be set but that's not right either.
Example code:
double data = 1.0;
label->setText( QString().number( data );
Look at the static function QString::number()
with format and precision arguments.
QString QString::number( double n, char format = 'g', int precision = 6 )
Reference: http://doc.qtsoftware.com/4.5/qstring.html#number-2
Why not use QString::sprintf() ?
QString().sprintf("%08d + rest of the string", 7);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With