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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exception after setting jdbc session management 2 51
What is JNDI datasource in spring 1 50
thymeleaf natural templating vs JSP 2 65
table example 4 19
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now