Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NumberFormat API question

 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre> format.setMinimumFractionDigits(2);</pre>
 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim ... PJ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic