PDA

View Full Version : QString formatting issue.



George Neil
22nd October 2009, 07:08
double dValue = 0.00200;
QString strValue = QString::number(dValue, 'e', 1);

The strValue is getting as 2.0e-03

I don't want the preceding zeros in the exponent part. How can i do that ?

kwisp
22nd October 2009, 07:34
i think only QRegExp helps you.

may be like this


QRegExp reg("(e[+-])([0]+)([0-9]+)");
int pos = reg.indexIn(strValue);
if(pos!=-1){
strValue.replace(reg,reg.cap(1) + reg.cap(3));
}

George Neil
22nd October 2009, 09:00
Great.... That works.....:)