Name
NumberFormat
Synopsis
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
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. getIntegerInstance( ),
getCurrencyInstance( ), and
getPercentInstance( ) return
NumberFormat objects for formatting numbers that
are integers, or represent monetary amounts or
percentages.
These methods return a NumberFormat suitable for
the default locale, or for the specified Locale
object. getAvailableLocales( ) returns an array of
locales for which NumberFormat objects are
available. In Java 1.4 and later, use setCurrency(
) to provide a java.util.Currency object
for use when formating monetary values. Note that the
NumberFormat class is 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.
Once you have created a suitable
NumberFormat object, you can customize its
localeindependent 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access