Project

General

Profile

Restricting decimal places in table cells.

Added by Rajeev Gajbhiye over 11 years ago

I am using WTableView to display a time series. The problem is that it displays number to several decimal places. How can I restrict it to only display say 3 decimal places?

Regards,

Rajeev.


Replies (4)

RE: Restricting decimal places in table cells. - Added by Thomas Suckow over 11 years ago

You just need to modify the delegate for the column

WItemDelegate * numdel2 = new WItemDelegate(parent);
numdel2->setTextFormat("%.2f");
tableView->setItemDelegateForColumn( colnum, numdel2 );

RE: Restricting decimal places in table cells. - Added by Rajeev Gajbhiye over 11 years ago

That worked!! I recall that when working on JWT, we had set "#0.000" as text format and it worked. With Wt, it doesn't. Any comments?

Regards,

Rajeev.

RE: Restricting decimal places in table cells. - Added by Thomas Suckow over 11 years ago

My guess is JWt and Wt use different formatters. Wt uses snprintf (or compatible) and my guess is JWt uses some java format syntax.

-Thomas

RE: Restricting decimal places in table cells. - Added by Koen Deforche over 11 years ago

Hey Thomas,

Indeed that's spot on. This is documented here (for C): http://www.webtoolkit.eu/wt/doc/reference/html/group__modelview.html#ga57b5cadd177847f51eaeb0cee23782c1 but the documentation doesn't point this out for Java. I've filed a bug for this: http://redmine.emweb.be/issues/1813

Regards,

koen

    (1-4/4)