aspose file tools*
The moose likes Java in General and the fly likes NumberFormat API question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "NumberFormat API question" Watch "NumberFormat API question" New topic
Author

NumberFormat API question

pjoisha
Ranch Hand

Joined: Mar 06, 2001
Posts: 123
Hi all,
I ran into a problem with the NumberFormat
class and I was wondering if someone had
a solution. Basically, if I run the
following snippet
NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(2);
format.setGroupingUsed(false);
System.out.println(format.format(5.795));
I get 5.8. However, what I really expected to see
was 5.80. Does anyone know of a nice workaround to
fix this problem?
TIA,
PJ
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
<pre> format.setMinimumFractionDigits(2);</pre>

"I'm not back." - Bill Harding, Twister
pjoisha
Ranch Hand

Joined: Mar 06, 2001
Posts: 123
Thanks Jim ... PJ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NumberFormat API question