Round.java

Download Round.java source file

// Round.java - a simple demo that shows how to format floating point numbers.
// Written March 2002 by Wayne Pollock, Tampa Florida USA.

import java.text.*;

class Round
{
    public static void main ( String [] args )
    {
        double someNumber = 3.6666666665;
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits( 2 );
        System.out.println( "original number:  " + someNumber );
        System.out.println( "formatted number: " + nf.format( someNumber ) );
    }
}