public class

CurrencyFormatter

extends AbstractNumberFormatter
java.lang.Object
   ↳ org.springframework.format.number.AbstractNumberFormatter
     ↳ org.springframework.format.number.CurrencyFormatter

Class Overview

A BigDecimal formatter for currency values.

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

Summary

Public Constructors
CurrencyFormatter()
Public Methods
BigDecimal parse(String text, Locale locale)
Parse a text String to produce a T.
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.
Protected Methods
NumberFormat getNumberFormat(Locale locale)
Obtain a concrete NumberFormat for the specified locale.
[Expand]
Inherited Methods
From class org.springframework.format.number.AbstractNumberFormatter
From class java.lang.Object
From interface org.springframework.format.Parser
From interface org.springframework.format.Printer

Public Constructors

public CurrencyFormatter ()

Public Methods

public BigDecimal parse (String text, Locale locale)

Parse a text String to produce a T.

Parameters
text the text string
locale the current user locale
Returns
  • an instance of T

public void setCurrency (Currency currency)

Specify the currency, if known.

public void setFractionDigits (int fractionDigits)

Specify the desired number of fraction digits. Default is 2.

public void setRoundingMode (RoundingMode roundingMode)

Specify the rounding mode to use for decimal parsing. Default is UNNECESSARY.

Protected Methods

protected NumberFormat getNumberFormat (Locale locale)

Obtain a concrete NumberFormat for the specified locale.

Parameters
locale the current locale
Returns
  • the NumberFormat instance (never null)