Round.java

Download Round.java

 1: // Round.java - a simple demo that shows how to format floating point numbers.
 2: // Written March 2002 by Wayne Pollock, Tampa Florida USA.
 3: 
 4: import java.text.*;
 5: 
 6: class Round
 7: {
 8:     public static void main ( String [] args )
 9:     {
10:         double someNumber = 3.6666666665;
11:         NumberFormat nf = NumberFormat.getInstance();
12:         nf.setMaximumFractionDigits( 2 );
13:         System.out.println( "original number:  " + someNumber );
14:         System.out.println( "formatted number: " + nf.format( someNumber ) );
15:     }
16: }