public class NumberFormatter extends java.lang.Object implements Formatter<java.lang.Number>
Formats numbers into localized Strings for display. This class relies heavily on the NumberFormat and DecimalFormat classes in the java.text package, and it is suggested that you become familiar with those classes before using custom formats.
Accepts the following named formatTypes (not case sensitive):
If a format type is not supplied the default value of "number" will be used. Format String can be either a custom pattern as used by NumberFormat, or one of the following named formats (not case sensitive):
Modifier and Type | Field and Description |
---|---|
protected static java.util.Set<java.lang.String> |
namedPatterns
Maintains a set of named formats that can be used instead of patterns.
|
Constructor and Description |
---|
NumberFormatter() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(java.lang.Number input)
Formats the number supplied as a String.
|
java.lang.String |
getFormatPattern()
Gets the named format string or number format pattern to use to format the number.
|
java.lang.String |
getFormatType()
Gets the format type to be used to render numbers as Strings.
|
java.util.Locale |
getLocale()
Gets the locale that output String should be in.
|
void |
init()
Instantiates the NumberFormat based on the information provided through setter methods.
|
void |
setFormatPattern(java.lang.String formatPattern)
Sets the named format string or number format pattern to use to format the number.
|
void |
setFormatType(java.lang.String formatType)
Sets the format type to be used to render numbers as Strings.
|
void |
setLocale(java.util.Locale locale)
Sets the locale that output String should be in.
|
protected static final java.util.Set<java.lang.String> namedPatterns
public void setFormatType(java.lang.String formatType)
setFormatType
in interface Formatter<java.lang.Number>
public java.lang.String getFormatType()
public void setFormatPattern(java.lang.String formatPattern)
setFormatPattern
in interface Formatter<java.lang.Number>
public java.lang.String getFormatPattern()
public void setLocale(java.util.Locale locale)
public java.util.Locale getLocale()
public void init()
public java.lang.String format(java.lang.Number input)
? Copyright 2005-2006, Stripes Development Team.