Solved

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

Posted on 2002-06-22
3
903 Views
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?

Thank!

Bun
0
Comment
Question by:bunwong
3 Comments
 
LVL 16

Accepted Solution

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

Expert Comment

by:rhariss
ID: 7102938
Hi
  Please try this code
    NumberFormat myformat = NumberFormat.getInstance();
    myformat.setMaximumFractionDigits(4);
    myformat.setMinimumFractionDigits(4);

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

   
Hari
 

0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

747 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

13 Experts available now in Live!

Get 1:1 Help Now