Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes double precision Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "double precision" Watch "double precision" New topic
Author

double precision

Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
i have a double... how do I print only 2 decimal places? Thanks.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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 ]

Mike Gershman
SCJP 1.4, SCWCD in process
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
thanks a lot.
 
jQuery in Action, 2nd edition
 
subject: double precision
 
Similar Threads
Float in J2ME
can't understand this..!!
Pre-assessment test from Oracle
WA #2 ..... word association
Hibernate: adding underscore to attibute names