[Qt-interest] Qt-interest Digest, Vol 15, Issue 144

Ross Driedger ross at earz.ca
Tue Feb 16 15:37:40 CET 2010


On 16-Feb-10, at 8:47 AM, qt-interest-request at trolltech.com wrote:

> Message: 1
> Date: Tue, 16 Feb 2010 14:26:49 +0100
> From: Mario Signorino <mario.signorino at gmail.com>
> Subject: [Qt-interest] QVariant imprecision?
> To: qt-interest at trolltech.com
> Message-ID:
> 	<bfc91c991002160526p5659bb80ja1030f3796459a92 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi all.
>
> The code:
>
>    double doubleFrom = 99999.99;
>    QVariant var(doubleFrom);
>    double doubleTo = var.toDouble();
>    qDebug() <<"doubleTo"<< doubleTo;
>    qDebug() <<"todouble"<< var.toDouble();
>    qDebug() <<"tostring"<< var.toString();
>    qDebug() <<"tofloat"<< var.toFloat();
>
> The output  (Qt 4.6.0 OpenSource):
>
>    doubleTo 100000
>    todouble 100000
>    tostring "99999.99"
>    tofloat 100000
>
> What?
> Am I missing something?

This is not a Qt or even a c++ issue.  It s a computer science issue.   
Simply put, expressing a value of continuous mathematics  in a  
discrete system like a computer will lead to slight inaccuracies.  The  
closest machine representation 99999.99 will be, most likely 100000.

Ross Driedger
ross_at_earz.ca




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100216/b6b30772/attachment.html 


More information about the Qt-interest-old mailing list