java.text.NumberFormat (JDK 1.1)
This class formats and parses numbers in a locale-specific way. As an abstract class, it cannot be instantiated directly, but it provides a number of static methods that return instances of a concrete subclass which you can use for formatting. The getInstance() method returns a NumberFormat object suitable for normal formatting of numbers in either the default locale or in a specified locale. getCurrencyInstance() and getPercentInstance() return NumberFormat objects for formatting numbers that represent monetary amounts and percentages in either the default locale or in a specified locale. getAvailableLocales() returns an array of locales for which NumberFormat objects are available.
Once you have created a suitable NumberFormat object, you may customize its locale-independent behavior with setMaximumFractionDigits(), setGroupingUsed() and similar set methods. In order to customize the locale-dependent behavior, you can use instanceof to test if the NumberFormat object is an instance of DecimalFormat, and if so, cast it to that type. The DecimalFormat class provides complete control over number formatting. Note, however, that a NumberFormat customized in this way may no longer be appropriate for the desired locale.
After creating and customizing a NumberFormat object, you can use the various format() methods to convert numbers to strings or string buffers, and you can use the parse() or parseObject() methods to convert strings to numbers.
The constants defined by this class are intended to be used by the FieldPosition object.
The NumberFormat class in not intended for the display of very large or very small numbers that require exponential notation, and it may not gracefully handle infinite or NaN (not-a-number) values.
public abstract classNumberFormatextends Format implements Cloneable { //Default Constructor: public NumberFormat()//Constantspublic static final intFRACTION_FIELD; public static final intINTEGER_FIELD; //Class Methodspublic static Locale[]getAvailableLocales(); public static final NumberFormatgetCurrencyInstance(); public static NumberFormatgetCurrencyInstance(LocaleinLocale); public static final NumberFormatgetInstance(); public static NumberFormatgetInstance(LocaleinLocale); public static final NumberFormatgetNumberInstance(); public static NumberFormatgetNumberInstance(LocaleinLocale); public static final NumberFormatgetPercentInstance(); public static NumberFormatgetPercentInstance(LocaleinLocale); //Public Instance Methodspublic Objectclone(); //Overrides Formatpublic booleanequals(Objectobj); //Overrides Objectpublic final StringBufferformat(Objectnumber, StringBuffertoAppendTo, FieldPositionpos); //Defines Formatpublic final Stringformat(doublenumber); public final Stringformat(longnumber); public abstract StringBufferformat(doublenumber, StringBuffertoAppendTo, FieldPositionpos); public abstract StringBufferformat(longnumber, StringBuffertoAppendTo, FieldPositionpos); public intgetMaximumFractionDigits(); public intgetMaximumIntegerDigits(); public intgetMinimumFractionDigits(); public intgetMinimumIntegerDigits(); public inthashCode(); //Overrides Objectpublic booleanisGroupingUsed(); public booleanisParseIntegerOnly(); public abstract Numberparse(Stringtext, ParsePositionparsePosition); public Numberparse(Stringtext) throws ParseException; public final ObjectparseObject(Stringsource, ParsePositionparsePosition); //Defines Formatpublic voidsetGroupingUsed(booleannewValue); public voidsetMaximumFractionDigits(intnewValue); public voidsetMaximumIntegerDigits(intnewValue); public voidsetMinimumFractionDigits(intnewValue); public voidsetMinimumIntegerDigits(intnewValue); public voidsetParseIntegerOnly(booleanvalue); }
Hierarchy:
Object->Format(Serializable, Cloneable)->NumberFormat(Cloneable)
Extended By:
ChoiceFormat, DecimalFormat
Passed To:
DateFormat.setNumberFormat()
Returned By:
DateFormat.getNumberFormat(), NumberFormat.getCurrencyInstance(), NumberFormat.getInstance(), NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()
Type Of:
DateFormat.numberFormat