// File: NumberOutput.java
import java.text.*;
import java.util.*;
public class NumberOutput
{
public static void main( String[] args )
{ NumberFormat form = new DecimalFormat();
System.out.println( "Number : " + -123.496 +
" Formatted : " + form.format( -123.496 ) );
System.out.println( "Number : " + 1234567890.496 +
" Formatted : " + form.format( 1234567890.496 ) );
String picture = "#,###.00;(#,###.00)";
try
{ form = new DecimalFormat( picture );
}
catch( IllegalArgumentException iae )
{ iae.printStackTrace();
System.out.println( "Illegal picture: " + picture );
System.exit(0);
}
System.out.println( "Number : " + -123.496 +
" Formatted : " + form.format( -123.496 ) );
System.out.println( "Number : " + 1234567890.496 +
" Formatted : " + form.format( 1234567890.496 ) );
}
}
|