QSqlQuery trunking double to int



  • Hi, I have a decimal field in an sql database that contains floating numbers, but when I do an sqlquery somehow it 's decimal part is truncated by qt as if it was an int?? anyone knows why?



  • Hi Misty River, can you post the code that you're using to select data from the data base? Also, It would help if you show the way you retrieve and handle the data after you execute your query.



  • @QSqlQuery qry;
    qry.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble);
    qry.exec("SELECT bd FROM users WHERE pseudo='"+ pseudo +"'");
    qry.next();

    QSqlRecord b = qry.record();
    bd= b.value("bd").toFloat();@
    

    That's basicly it... I retrieve the Decimal value from the database and store it in a float or double.. I understand that by default Qt is suppose to use LowPrecisionDouble as policy so you can blurr out that line..



  • Hi Misty River, sorry for the delay on my answer.

    I've been reading the docs about this and yes, LowPrecisionDouble is the default policy for numerical precision. However, the QSqlQuery Class Reference states that The Oracle driver, for example, can retrieve numerical values as strings to prevent the loss of precision. If high precision doesn't matter, use this method to increase execution speed by bypassing string conversions., this may be the reason of why your numbers are truncated, try using "HighPrecision" instead and see what happens.



  • Hi,

    Yeah I tried what you said and I also tried all the different types of floats in SQL and still qt trunks it.. I really have no clue what could cause that but thanks for your input.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.