How to display a Float with the format 0.0000 in a JTable?

Posted on 2002-06-22
Last Modified: 2006-11-17
I have a JTable displaying values for a Float data type. I would like to have the numbers displayed to 4 decimal points. e.g:

1.7 should be 1.7000
1 should be 1.0000
1.23456 should be 1.2346

But I don't know how to format display in a JTable cell. A few hours of doc digging did not help.

Is there any simple way to do it?


Question by:bunwong
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Accepted Solution

heyhey_ earned 100 total points
ID: 7101351
you have to
1. implement your own cell renderer;
2. use DecimalFormat to format the output text.

Expert Comment

ID: 7102938
  Please try this code
    NumberFormat myformat = NumberFormat.getInstance();

   use this code
   float f=1.7f;
  System.out.println(new DecimalFormat("#########.0000").format(f));



Author Comment

ID: 7105473
Thanks, I'm all set now.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 87
JavaFX TableView not displaying correctly 3 109
What's wrong with this code? 4 36
Java array sort 10 35
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question