[Qt-interest] SQL (ODBC) retreiving doubles incorrectly

Julien Cugnière julien.cugniere at gmail.com
Fri Oct 2 14:51:21 CEST 2009


2009/10/2 Andre Somers <andre at familiesomers.nl>
> Julien Cugnière wrote:
> > You can try using query.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble).
> >
> > If you don't, Qt often returns number as strings in order to preserve
> > the precision of the database, which can be greater than that of a
> > double. AFAIK, the exact format of the string is database-dependant,
> > and there's no guarantee it can be parsed by QString::toDouble.
> >
> Thanks for the tip, I had not looked into this option before.
> Unfortunately, it makes things worse. Instead of an QVariant(QString,
> "E-3") on my debug, I now get an QVariant(, ). That probably means an
> empty or invalid value. Not a real improvement over the string...

Indeed :-(

> I have hacked around the issue for now by multiplying the value I am
> after in my query, and deviding it by the same value again after
> retreiving it. Still, this is an extremely ugly hack, and I'd like to
> get rid of it...

A slightly better hack would be to prepend "0.0" to the value you get
if it starts with 'E' or 'e'. Then you can use QString::toDouble().

--
Julien Cugnière




More information about the Qt-interest-old mailing list