precision of float field in qtableview
I have a qtableview to display result of a sql query.I have problems with filelds that defined to have float data types.
Table is defined in database as:
table1(studentId int,
studentGrade int,
weight float)
Here is how my table in database look like:
Code:
studentId studentGrade weight
1 80 0.7
2 90 0.8
i fill qSqlQueryModel with query (select * from table1) and then set model to qtableview.
But float fields' precision is lost.
Here is how my QTabelView looks like:
Code:
studentId studentGrade weight
1 80 0.69999999
2 90 0.7999999
anybody knows how to fix this?? i just want to see 0.7 and 0.8 in my qtableview.
thanx in adnavce.
Re: precision of float field in qtableview
That is because floats and doubles cannot "exactly" store 0.7 or 0.8 (see Wikipedia: http://en.wikipedia.org/wiki/Floatin...uracy_problems).
Do you use QString::setNum( double n, char format = 'g', int precision = 6 ) for setting the string?
Play around with format an precision. precision rounds the number. So if you want 0.7 and not 0.70 or 0.69999 use precision = 1.
Re: precision of float field in qtableview
Did you solve this problem? I am having the same problem and converting to string is nice but bad for sorting and alignment.
Re: precision of float field in qtableview
Quote:
Originally Posted by
mstegehu
Did you solve this problem? I am having the same problem and converting to string is nice but bad for sorting and alignment.
Later years, someone can help me?
Re: precision of float field in qtableview
Quote:
someone can help me?
Help you do what? Be specific.