Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-06-22
3
Medium Priority
?
962 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
[X]
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
3 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 300 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

618 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