views:

153

answers:

1

I'm trying to format an arbitrary length decimal so all of the numbers to the left of the decimal point are displayed but a maximum of 2 to the right are displayed (if they are non-zero). How can I specify in a DecimalFormat to display all numbers to the left rather than specifying the number of digits ahead of time?

thanks, Jeff

+4  A: 

This might help you

DecimalFormat formatter = new DecimalFormat("#.##");

inputs/outputs:

System.out.println(formatter.format(-1234.567));         
System.out.println(formatter.format(1239.00));                
System.out.println(formatter.format(567));
System.out.println(formatter.format(0.2342523));

gave

-1234.57
1239
567
0.23
Aviator
thanks. didn't realize the one # on the left side would get all the numbers. i probably should have just tried it. appreciate the quick help.
Jeff Storey
u r most welcome :)
Aviator