Hi,
I have to get a value from a database, for example, 2.3000. Must compare this value with the result of this calculation, as code:
...
double y = 2.3;
double x = qry.value(0).toDouble(); // Take 2.30000 in the database, this example;
qDebug() << y << x; // Ok, show 2.3 value for x and y;
double z = x - y; // It's result in -2.66454e-15!
if (z < 0.00) {
...
}
else
{
...
}
QSqlQuery qry;
...
double y = 2.3;
double x = qry.value(0).toDouble(); // Take 2.30000 in the database, this example;
qDebug() << y << x; // Ok, show 2.3 value for x and y;
double z = x - y; // It's result in -2.66454e-15!
if (z < 0.00) {
...
}
else
{
...
}
To copy to clipboard, switch view to plain text mode
If I make a calculation explicitly declare the values for the variables x and y, result is correct.
I created a method to convert a QString to a double that is working (code below). Any hint to resolve this as I use this function to work around the problem?
...
double y = 2.3;
QString sx
= qry.
value(0).
toString();
double x = myfunction->toDouble(sx);
double z = x - y; // It's OK, result 0
...
QSqlQuery qry;
...
double y = 2.3;
QString sx = qry.value(0).toString();
double x = myfunction->toDouble(sx);
double z = x - y; // It's OK, result 0
...
To copy to clipboard, switch view to plain text mode
Thanks,
Marcelo Estanislau Geyer
Bookmarks