Link to home
Start Free TrialLog in
Avatar of bunwong
bunwong

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rhariss
rhariss

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
 

Avatar of bunwong

ASKER

Thanks, I'm all set now.