PDA

View Full Version : QTableView and precsions



baray98
24th June 2009, 17:08
I use QSqlQueryModel and QTableView in my application to browse data in a database. My database stores some number with decimals points in it. I want my view to just show me just 2 digit after the decimal point. this must be doable is it not? and if so what is the easiest way to do this.

baray98

wysota
24th June 2009, 20:49
You can either ask the database to trim the numbers using a proper sql function or you can do the trimming after you receive the values using, for instance, QString::number() where you can pass the precision you want.

baray98
26th June 2009, 03:56
I am not sure how can i trim using SQL statement ( newbie ) , if you can tell me how please do ..

One thing i could do it inherit QSqlTableModel then trim it right there..is this what you meant by using QString::number()?


baray98

Lykurg
26th June 2009, 07:17
That isn't meant cruel, but you should be able to read docs and find such easy informations! Especially if the doc are very well organized like the MySQL one:

MySQL 6.0 Reference Manual :: 11 Functions and Operators :: 11.5 Numeric Functions

There is a nice function called: ROUND(X,D) (http://dev.mysql.com/doc/refman/6.0/en/mathematical-functions.html#function_round)