aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Imprecise jtable float values from view Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Imprecise jtable float values from view" Watch "Imprecise jtable float values from view" New topic
Author

Imprecise jtable float values from view

antonio espinosa
Greenhorn

Joined: Jul 30, 2012
Posts: 14
hello dear friends i have this issue i'm working with a jtable and queried results from a sql server database and the table shows 0.0 a float value after that i evaluate the cell and it says it's value is 0.03
what is wrong ? my sql query says its 0 not 0.03, how to match the jtable values and my queried results?.

thank you very much fellows


Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1157
    
    3

What do you mean by you evaluate the cell?
Are you doing some computation on the cell value?
What CellRender are you using?

Try printing out the value returned from the DB, the value you are actually adding to the JTable (is it a float value or String) and then immediately get the value back from the JTable and print that out too. Are they all 0.0?
antonio espinosa
Greenhorn

Joined: Jul 30, 2012
Posts: 14
What do you mean by you evaluate the cell? well i mean to show the value of the cell.
Are you doing some computation on the cell value? any
What CellRender are you using? a modified version of this model My model


i saw the values wich i got from the database (the cost was 0) and it was as i expected, then i read the populated values of the model and it was ok.

finally i discovered this:



HOWever the jtable view shows 0.0

thank you very much Tony.


if it helps i'l show you my process to create the jtablemodel


Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1157
    
    3


That won't compile, you can't assign a String to a variable of type Float.
antonio espinosa
Greenhorn

Joined: Jul 30, 2012
Posts: 14
Tony Docherty wrote:
That won't compile, you can't assign a String to a variable of type Float.


ok right at some point i commited an error typing it at java ranch this is the real code sorry it was a dumb error of mine

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1157
    
    3

Ok so where do you set a value into your Cost variable (which then prints out 0.03).
antonio espinosa
Greenhorn

Joined: Jul 30, 2012
Posts: 14
oh my good! this fixed on its own i cant believe it... thank you very much for your time really the output was 0.03... now i want to ask you an advice









i do too much conversions wich would be the best way to get the value from de model.


i hope you are not mad about this.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1157
    
    3

Why not just store the data in your model in their natural class types (ie as Integers and/or Doubles) then you won't have to convert to and from strings.
It is not unusual for JTables to have models which have different data types in different columns.
antonio espinosa
Greenhorn

Joined: Jul 30, 2012
Posts: 14
i'll look for this. i'm very pleased because you are very kind
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1157
    
    3

My pleasure.
Check out the Java tutorial http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Imprecise jtable float values from view
 
Similar Threads
JTable
JTable
JTable
Passing Database query results through a method to a JTable
EDITABLE JTable and SQL QUERY