View Full Version : QString formatting issue.

George Neil
22nd October 2009, 08: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 ?

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

may be like this

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

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