org.springframework.ui.format.number
Class CurrencyFormatter

java.lang.Object
  extended by org.springframework.ui.format.number.AbstractNumberFormatter
      extended by org.springframework.ui.format.number.CurrencyFormatter
All Implemented Interfaces:
Formatter<Number>

public final class CurrencyFormatter
extends AbstractNumberFormatter

A BigDecimal formatter for currency values.

Delegates to NumberFormat.getCurrencyInstance(Locale). Configures BigDecimal parsing so there is no loss of precision. Can apply a specified RoundingMode to parsed values.

Since:
3.0
Author:
Keith Donald, Juergen Hoeller
See Also:
AbstractNumberFormatter.setLenient(boolean), setRoundingMode(java.math.RoundingMode)

Constructor Summary
CurrencyFormatter()
           
 
Method Summary
protected  NumberFormat getNumberFormat(Locale locale)
          Obtain a concrete NumberFormat for the specified locale.
 BigDecimal parse(String formatted, Locale locale)
          Parse an object from its formatted representation.
 void setCurrency(Currency currency)
          Specify the currency, if known.
 void setFractionDigits(int fractionDigits)
          Specify the desired number of fraction digits.
 void setRoundingMode(RoundingMode roundingMode)
          Specify the rounding mode to use for decimal parsing.
 
Methods inherited from class org.springframework.ui.format.number.AbstractNumberFormatter
format, setLenient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CurrencyFormatter

public CurrencyFormatter()
Method Detail

setFractionDigits

public void setFractionDigits(int fractionDigits)
Specify the desired number of fraction digits. Default is 2.


setRoundingMode

public void setRoundingMode(RoundingMode roundingMode)
Specify the rounding mode to use for decimal parsing. Default is RoundingMode.UNNECESSARY.


setCurrency

public void setCurrency(Currency currency)
Specify the currency, if known.


parse

public BigDecimal parse(String formatted,
                        Locale locale)
                 throws ParseException
Description copied from interface: Formatter
Parse an object from its formatted representation.

Specified by:
parse in interface Formatter<Number>
Overrides:
parse in class AbstractNumberFormatter
Parameters:
formatted - a formatted representation
locale - the user's locale
Returns:
the parsed object
Throws:
ParseException - when a parse exception occurs

getNumberFormat

protected NumberFormat getNumberFormat(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)