Spring Framework

org.springframework.format.number
Class NumberFormatter

java.lang.Object
  extended by org.springframework.format.number.AbstractNumberFormatter
      extended by org.springframework.format.number.NumberFormatter
All Implemented Interfaces:
Formatter<java.lang.Number>, Parser<java.lang.Number>, Printer<java.lang.Number>

public class NumberFormatter
extends AbstractNumberFormatter

A general-purpose Number formatter.

Delegates to NumberFormat.getInstance(Locale). Configures BigDecimal parsing so there is no loss in precision. Allows configuration over the decimal number pattern. The AbstractNumberFormatter.parse(String, Locale) routine always returns a BigDecimal.

Since:
3.0
Author:
Keith Donald, Juergen Hoeller
See Also:
setPattern(java.lang.String), AbstractNumberFormatter.setLenient(boolean)

Constructor Summary
NumberFormatter()
          Create a new NumberFormatter without a pattern.
NumberFormatter(java.lang.String pattern)
          Create a new NumberFormatter with the specified pattern.
 
Method Summary
 java.text.NumberFormat getNumberFormat(java.util.Locale locale)
          Obtain a concrete NumberFormat for the specified locale.
 void setPattern(java.lang.String pattern)
          Sets the pattern to use to format number values.
 
Methods inherited from class org.springframework.format.number.AbstractNumberFormatter
parse, print, setLenient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberFormatter

public NumberFormatter()
Create a new NumberFormatter without a pattern.


NumberFormatter

public NumberFormatter(java.lang.String pattern)
Create a new NumberFormatter with the specified pattern.

Parameters:
pattern - the format pattern
See Also:
setPattern(java.lang.String)
Method Detail

setPattern

public void setPattern(java.lang.String pattern)
Sets the pattern to use to format number values. If not specified, the default DecimalFormat pattern is used.

See Also:
DecimalFormat.applyPattern(String)

getNumberFormat

public java.text.NumberFormat getNumberFormat(java.util.Locale locale)
Description copied from class: AbstractNumberFormatter
Obtain a concrete NumberFormat for the specified locale.

Specified by:
getNumberFormat in class AbstractNumberFormatter
Parameters:
locale - the current locale
Returns:
the NumberFormat instance (never null)

Spring Framework