PDA

View Full Version : Strange QString::number behaviour



sastrian
7th September 2012, 08:27
Hello

I am facing a strange behaviour of QString::number that I can not explain even after reading the documentation over and over again.



qDebug() << QString::number( 62.5, 'g' );
qDebug() << QString::number( 62.5, 'g', 1 );
qDebug() << QString::number( 62.5, 'g', 2 );
qDebug() << QString::number( 62.5, 'g', 4 );
qDebug() << QString::number( 62.5, 'g', 5 );
qDebug() << QString::number( 62.5, 'g', 6 );


Produces this output:



"62.5"
"6e+01"
"62"
"62.5"
"62.5"
"62.5"


Now I dont understand why the "62" without the .5 result of the result line from "qDebug() << QString::number( 62.5, 'g', 2 ); "


Any explaination on what I am doing wrong? The format options 'e' and 'f' are not interessting for me right now.

Greetings
sas

pkj
7th September 2012, 09:29
g/ G return whichever among e/E or F is more concise.
with 2 precision, f gives 62.5, e gives 62, with trailing zeroes being omitted. Which is more concise?
Both g and G never made sense to use. use f or e to be sure.