Java Number Format

In programming languages, a pattern of special characters is used to specify the format of the number. In java this is achieved by the java

Java Number Format

Java Number Format

     

In programming languages, a pattern of special characters is used to specify the format of the number. In java this is achieved by the java.text.NumberFormat class. NumberFormat is the abstract base class for all number formats. It provides the interface for formatting and parsing numbers such as Strings to and from doubles and longs, and vice versa. It also helps you to format and parse numbers for any locale.
 
A format is given by a pattern of symbols. For example, the pattern "0.000" indicates that the number should begin with 0 if it is less than 1.0 and that the number of decimal places will be 3 and padded with 0 if necessary to reach 3 places.
 
Another example, the pattern "0.###" indicates that the number should begin with 0 if it is less than 1.0 and that the number of decimal places will be up to 3 and padded with blanks if the fraction needs less than 3 places.
  
Read example at:

http:/www.roseindia.net/java/beginners/DecimalFormatExample.shtml