Reading numeric from DBRequest



  • Hi everybody

    my problem is to get the right numeric value with 20 digits out of the database.

    I connect to an Microsoft SQL Server over ODBC. I use the SQL Server Native Client 10.0 driver.
    Now comes the problem when i try to select numeric values stored in the database. I have in the Database numeric(20,0) values. In the Result comes a QVariant with the type double.
    When i print the double or transform the double to a string there are problems with the last digits.
    For Example the value in the Database is 10903012224000000001 and in the resultset i got it is 10903012224000000000 (the last 1 changed to 0) or 10903012224000001555 is changed to 10903012224000002048
    Is there any solution to get the right value? I can´t change anythink at the database because the database and the size of the Key as a numeric with 20 digits is given.

    Hope for Help
    Schubi



  • Hi I found a "bugreport":https://bugreports.qt-project.org/browse/QTBUG-10451

    The solution is to set numericalPrecisionPolicy from LowPrecisionDouble to HighPrecision the following codeline is to add and then the qVariant is qString and everythink works fine

    @
    db.setNumericalPrecisionPolicy(QSql::HighPrecision);
    @


Log in to reply
 

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