How to correctly read DECIMAL values from MySQL with QSqlQuery
-
Having a table in MySQL with a column of type DECIMAL, I am wondering how to read this value properly in my Qt application. To me it seems like it is handled like a double when you retrieve it using QSqlQuery. Is this correct? Doesn't this risk losing precision?
To quote https://spin.atomicobject.com/2014/08/14/currency-rounding-errors/
Now that the database is storing the monetary values accurately, you don’t want to do anything to lose that accuracy when retrieving values from it. [...] when using Java’s Hibernate ORM, you need to specify the variable as a BigDecimal not a Float or Double
-
Hi,
Indeed, DECIMAL is mapped to double in the MySQL plugin.
You should do some testing with the values you are going to use.
-
What does this mean exactly? That the SQL classes of Qt cannot be used if you want the precision of DECIMAL?