• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Imprecise jtable float values from view

 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That won't compile, you can't assign a String to a variable of type Float.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so where do you set a value into your Cost variable (which then prints out 0.03).
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'll look for this. i'm very pleased because you are very kind
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
Check out the Java tutorial http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic