This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get rid of auto hex numerals display

 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a java table that gets/saves data from/to a sql table. The field in the database is set to: float (type), 15 (length) && 3 precision.

Whenever I enter a value 9 000 000 or under it shows me the value I typed and the value saved in the database is correct but as soon
as its greater than 7 characters eg: 11 000 000 then on screen it immediately converts to hex value 1.1E7 but in the database it is still
saved correctly as 11 000 000.

Any ideas on how I can stop the value from displaying in hex form?

Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use simple printing of float / double. Use better formatting using java.util.Formatter, for instance using String.format or PrintStream.printf:
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maja Gralewska wrote: . . . converts to hex value 1.1E7 . . .
That isn't hex, but scientific notation.

Anyway, Rob has already given you a solution.
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im sorry but i am confused as to how i would use that? I am not trying to print the value out, when a user enters a value in my gui table and if say that value is 11000000 and tabs to the next col then it immediately defaults the value to 1.1E7. I need the value to stay what the user has typed on screen. Maybe I am not explaining correctly I have added a bmp to show what i mean more clearly.

Thanks for your help.
Filename: statExample.bmp
Description: Example of problem
File size: 533 Kbytes
[Download statExample.bmp] Download Attachment
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out how TableCellRender works. There's a good example in the Java Tutorial; you can find a link to the right section from the JTable Javadoc page.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a difference between what the number IS and how it is DISPLAYED. "10", "TEN", "X", "1010" "0xA", and "1E1" all represent the same number, it's simply a difference in how you present the data to the user. It's a display issue, not a data issue.

I'm not sure how tables would work - is there a property on the table to prevent that? some kind of formatting?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what TableCellRenderers do. They take a value and return a Component to display it. Similarly, TableCellEditor returns a Component to edit a value, and return the new edited value from the Component when done.
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, this kinda helped but also kind of didn't, when i click finish and reload the screen the data now loads as a normal decimal but in the
initial entry on tab it still auto changes to scientific, i have tried a few thing but i cant seem to get it to work straight after tab.

any ideas? Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic