File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTextField and decimal number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField and decimal number" Watch "JTextField and decimal number" New topic

JTextField and decimal number

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
I am trying to print out a decimal number like 13.45 in JTextField. I do convert this number from a Double to String and send it to JTextField, but in the applet all I get is 1345 followed by a small square. I tried to type 13.45 in the text field, but it does not let me print "." What should I do? Should I use another component to display decimal numbers?

All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
JTextField is fine. How are you converting to a String. Are you using DecimalFormat or just doing a toString? You should use the DecimalFormat to control how you want the number to appear.
I agree. Here's the link:
subject: JTextField and decimal number
jQuery in Action, 3rd edition