Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double precision

 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a double... how do I print only 2 decimal places? Thanks.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.text.NumberFormat;

NumberFormat NF = NumberFormat.getNumberInstance();
NF.setMaximumFractionDigits(2);
NF.setMinimumFractionDigits(2);

System.out.println( "d = " + NF.format(d) );

[ October 10, 2004: Message edited by: Mike Gershman ]
[ October 10, 2004: Message edited by: Mike Gershman ]
 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic