Top Description Fields Constructors Methods
org.springframework.format.number

public Class CurrencyStyleFormatter

extends AbstractNumberFormatter
Class Inheritance
Imports
java.math.BigDecimal, .RoundingMode, java.text.DecimalFormat, .NumberFormat, .ParseException, java.util.Currency, .Locale, org.springframework.lang.Nullable

A BigDecimal formatter for number values in currency style.

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

Authors
Keith Donald, Juergen Hoeller
Since
4.2
See Also
setLenient, setRoundingMode

Field Summary

Modifier and TypeField and Description
private Currency
private int
private String
private RoundingMode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected NumberFormat
getNumberFormat(Locale
the current locale
locale
)

Implements abstract org.springframework.format.number.AbstractNumberFormatter.getNumberFormat.

Obtain a concrete NumberFormat for the specified locale.

public BigDecimal
parse(String
the text string
text
,
Locale
the current user locale
locale
)

Overrides org.springframework.format.number.AbstractNumberFormatter.parse.

Implements org.springframework.format.Parser.parse.

Parse a text String to produce a T.

public void
setCurrency(Currency currency)

Specify the currency, if known.

public void
setFractionDigits(int fractionDigits)

Specify the desired number of fraction digits.

public void
setPattern(String pattern)

Specify the pattern to use to format number values.

public void
setRoundingMode(RoundingMode roundingMode)

Specify the rounding mode to use for decimal parsing.

Inherited from org.springframework.format.number.AbstractNumberFormatter:
printsetLenient

Field Detail

currencyback to summary
private Currency currency
Annotations
@Nullable
fractionDigitsback to summary
private int fractionDigits
patternback to summary
private String pattern
Annotations
@Nullable
roundingModeback to summary
private RoundingMode roundingMode
Annotations
@Nullable

Constructor Detail

CurrencyStyleFormatterback to summary
public CurrencyStyleFormatter()

Method Detail

getNumberFormatback to summary
protected NumberFormat getNumberFormat(Locale locale)

Implements abstract org.springframework.format.number.AbstractNumberFormatter.getNumberFormat.

Doc from org.springframework.format.number.AbstractNumberFormatter.getNumberFormat.

Obtain a concrete NumberFormat for the specified locale.

Parameters
locale:Locale

the current locale

Returns:NumberFormat

the NumberFormat instance (never null)

Annotations
@Override
parseback to summary
public BigDecimal parse(String text, Locale locale) throws ParseException

Overrides org.springframework.format.number.AbstractNumberFormatter.parse.

Implements org.springframework.format.Parser.parse.

Doc from org.springframework.format.Parser.parse.

Parse a text String to produce a T.

Parameters
text:String

the text string

locale:Locale

the current user locale

Returns:BigDecimal

an instance of T

Annotations
@Override
Exceptions
ParseException:
when a parse exception occurs in a java.text parsing library
setCurrencyback to summary
public void setCurrency(Currency currency)

Specify the currency, if known.

setFractionDigitsback to summary
public void setFractionDigits(int fractionDigits)

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

setPatternback to summary
public void setPattern(String pattern)

Specify the pattern to use to format number values. If not specified, the default DecimalFormat pattern is used.

See Also
java.text.DecimalFormat#applyPattern(String)
setRoundingModeback to summary
public void setRoundingMode(RoundingMode roundingMode)

Specify the rounding mode to use for decimal parsing. Default is java.math.RoundingMode#UNNECESSARY.