formatting floats in a table



Hi,
i have a table whose columns can contain either Strings, Integers, or
Floats. I also allow sorting by clicking on the header of a column.

my question is, i need to display only two decimal places for columns
that display floats. How can i do this and still maintain accurate
sorting for those columns? Currently, it seems most of the formating
functions return Strings, and that may cause the sorting to be
incorrect for columns that are suppose to display numbers.

Also i am trying to do this generically using a custom
TableCellRenderer class i have written. This renderer has a member
variable called "formatString". Basically, when the JTable is
initalized, i read some config info, one of which tells me what columns
need formatting and how they should be formatted. I then instantiate
the TableCellRenderer class, assign the formatString (if required),
then call TableColumn.setCellRenderer.
Now i just need to know how i can apply that formatString to the Value
and still maintain the underlying class type of Value so that i can be
properly sorted....

.



Relevant Pages

  • Re: Referencing Items in a List of Tuples
    ... I find references to sorting a list of tuples, ... two items are 3-character strings, the remaining 28 itmes are floats. ...
    (comp.lang.python)
  • Re: formatting floats in a table
    ... i have a table whose columns can contain either Strings, Integers, or Floats. ... TableCellRenderer class i have written. ... the TableCellRenderer class, assign the formatString, ... YourTableModel yourTableModel = ... ...
    (comp.lang.java.help)
  • Re: Console.WriteLine(s) Is Missing Line Terminator?
    ... I thought they recommend the & operator for concatenating ... When outputting strings, you could try using FormatString ... by calling an integer's ToString method. ...
    (microsoft.public.dotnet.general)
  • Re: format frage
    ... keine Strings übergibt, sondern eben float oder integers. ... liefert mir eine exception das der formatstring oder die arguments nicht passen?? ...
    (de.comp.lang.delphi.misc)