[PyQt] QVariant.toFloat()

Darryl Wallace darryl.wallace at prosensus.ca
Thu Jan 14 13:50:36 GMT 2010


> when I use toDouble() I obtain a data in this format:
> (9.5, True)

The method definition for "toDouble" in C++ is:

QVariant.toDouble(bool *ok=0)

The "ok" value will be true if the conversion to a double was successful.
 Because passing a pointer into a function this way is not "Pythonic," Phil
had it return the value and success in a tuple (at least I think that was
the motivation).

So this means you need to index the first value of the tuple, e.g. value =

> When it should be a float 9.50 (cause like I said, is what I have in DB).
> How can I get it 2 decimals positions?

As Andreas noted in the next post, the decimal places shouldn't matter
because it's a double precision floating point value.  If you want it to be
placed in your data base as a string with two decimal places, then export it
to the database with a formatted string.  But I'm not sure this is what
you're asking.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100114/ebaeb665/attachment.html>

More information about the PyQt mailing list