aspose file tools*
The moose likes Java in General and the fly likes how to get rid of auto hex numerals display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get rid of auto hex numerals display" Watch "how to get rid of auto hex numerals display" New topic
Author

how to get rid of auto hex numerals display

Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
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.


Potrzeba jest matka wynalazków
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Don't use simple printing of float / double. Use better formatting using java.util.Formatter, for instance using String.format or PrintStream.printf:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
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

Joined: Sep 26, 2008
Posts: 92
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.


[Download statExample.bmp] Download

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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

Joined: Oct 02, 2003
Posts: 11480
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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

Joined: Sep 26, 2008
Posts: 92
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get rid of auto hex numerals display