Top Description Fields Constructors Methods
org.joda.money.format

public final Class MoneyAmountStyle

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.text.DecimalFormat, .DecimalFormatSymbols, .NumberFormat, java.util.Locale, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

Defines the style that the amount of a monetary value will be formatted with.

The style contains a number of fields that may be configured based on the locale:

The style can be used in three basic ways.

This class is immutable and thread-safe.

Field Summary

Modifier and TypeField and Description
private final boolean
absValue

Whether to use the absolute value instead of the signed value.

public static final MoneyAmountStyle
ASCII_DECIMAL_COMMA_GROUP3_DOT

A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a dot.

public static final MoneyAmountStyle
ASCII_DECIMAL_COMMA_GROUP3_SPACE

A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a space.

public static final MoneyAmountStyle
ASCII_DECIMAL_COMMA_NO_GROUPING

A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts.

public static final MoneyAmountStyle
ASCII_DECIMAL_POINT_GROUP3_COMMA

A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a comma.

public static final MoneyAmountStyle
ASCII_DECIMAL_POINT_GROUP3_SPACE

A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a space.

public static final MoneyAmountStyle
ASCII_DECIMAL_POINT_NO_GROUPING

A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts.

private final int
decimalPointCharacter

The character used for the decimal point.

private final int
extendedGroupingSize

The size of each group.

private final boolean
forceDecimalPoint

Whether to always require the decimal point to be visible.

private final int
groupingCharacter

The character used for grouping.

private final int
groupingSize

The size of each group.

private final GroupingStyle
groupingStyle

Whether to group or not.

private static final ConcurrentMap<Locale, MoneyAmountStyle>
LOCALIZED_CACHE

Cache of localized styles.

public static final MoneyAmountStyle
LOCALIZED_GROUPING

A style that will be filled in with localized values using the locale of the formatter.

public static final MoneyAmountStyle
LOCALIZED_NO_GROUPING

A style that will be filled in with localized values using the locale of the formatter.

private final int
negativeCharacter

The prefix string when the amount is negative.

private final int
positiveCharacter

The character representing the positive sign.

private static final long
serialVersionUID

Serialization version.

private final int
zeroCharacter

The character defining zero, and thus the numbers zero to nine.

Constructor Summary

AccessConstructor and Description
private
MoneyAmountStyle(int
the zero character
zeroCharacter
,
int
the positive sign
positiveCharacter
,
int
the negative sign
negativeCharacter
,
int
the decimal point character
decimalPointCharacter
,
GroupingStyle
the grouping style, not null
groupingStyle
,
int
the grouping character
groupingCharacter
,
int
the grouping size
groupingSize
,
int
the extended grouping size
extendedGroupingSize
,
boolean
whether to always use the decimal point character
forceDecimalPoint
,
boolean
true to output the absolute value rather than the signed value
absValue
)

Constructor, creating a new monetary instance.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if equal
equals
(Object
the other style, null returns false
other
)

Overrides java.lang.Object.equals.

Compares this style with another.

public Character

Returns:

the decimal point character, null if to be determined by locale
getDecimalPointCharacter
()

Gets the character used for the decimal point.

public Integer

Returns:

the size of each group, null if to be determined by locale
getExtendedGroupingSize
()

Gets the size of each group, not typically used.

public Character

Returns:

the grouping character, null if to be determined by locale
getGroupingCharacter
()

Gets the character used to separate groups, typically thousands.

public Integer

Returns:

the size of each group, null if to be determined by locale
getGroupingSize
()

Gets the size of each group, typically 3 for thousands.

public GroupingStyle

Returns:

the grouping style, not null
getGroupingStyle
()

Gets the style of grouping required.

private static MoneyAmountStyle

Returns:

the symbols, never null
getLocalizedStyle
(Locale
the Locale used to get the correct DecimalFormatSymbols
locale
)

Gets the prototype localized style for the given locale.

public Character

Returns:

the format for negative amounts, null if to be determined by locale
getNegativeSignCharacter
()

Gets the character used for the negative sign character.

public Character

Returns:

the format for positive amounts, null if to be determined by locale
getPositiveSignCharacter
()

Gets the character used for the positive sign character.

public Character

Returns:

the zero character, null if to be determined by locale
getZeroCharacter
()

Gets the character used for zero, and defining the characters zero to nine.

public int

Returns:

a hash code
hashCode
()

Overrides java.lang.Object.hashCode.

A suitable hash code.

public boolean

Returns:

true to output the absolute value, false for the signed value
isAbsValue
()

Returns true if the absolute value setting.

public boolean

Returns:

whether to force the decimal point on output
isForcedDecimalPoint
()

Gets whether to always use the decimal point, even if there is no fraction.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
localize
(Locale
the locale to use, not null
locale
)

Returns a MoneyAmountStyle instance configured for the specified locale.

public static MoneyAmountStyle

Returns:

the new instance, never null
of
(Locale
the locale to use, not null
locale
)

Gets a localized style.

public String

Returns:

a string summarising the style, never null
toString
()

Overrides java.lang.Object.toString.

Gets a string summary of the style.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withAbsValue
(boolean
true to output the absolute value, false for the signed value
absValue
)

Returns a copy of this style with the specified absolute value setting.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withDecimalPointCharacter
(Character
the decimal point character, null if to be determined by locale
decimalPointCharacter
)

Returns a copy of this style with the specified decimal point character.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withExtendedGroupingSize
(Integer
the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale
extendedGroupingSize
)

Returns a copy of this style with the specified extended grouping size.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withForcedDecimalPoint
(boolean
true to force the use of the decimal point, false to use it if required
forceDecimalPoint
)

Returns a copy of this style with the specified decimal point setting.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withGroupingCharacter
(Character
the grouping character, null if to be determined by locale
groupingCharacter
)

Returns a copy of this style with the specified grouping character.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withGroupingSize
(Integer
the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale
groupingSize
)

Returns a copy of this style with the specified grouping size.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withGroupingStyle
(GroupingStyle
the grouping style, not null
groupingStyle
)

Returns a copy of this style with the specified grouping setting.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withNegativeSignCharacter
(Character
the negative character, null if to be determined by locale
negativeCharacter
)

Returns a copy of this style with the specified negative sign character.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withPositiveSignCharacter
(Character
the positive character, null if to be determined by locale
positiveCharacter
)

Returns a copy of this style with the specified positive sign character.

public MoneyAmountStyle

Returns:

the new instance for chaining, never null
withZeroCharacter
(Character
the zero character, null if to be determined by locale
zeroCharacter
)

Returns a copy of this style with the specified zero character.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

absValueback to summary
private final boolean absValue

Whether to use the absolute value instead of the signed value.

ASCII_DECIMAL_COMMA_GROUP3_DOTback to summary
public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_DOT

A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a dot. Forced decimal point is disabled.

ASCII_DECIMAL_COMMA_GROUP3_SPACEback to summary
public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_SPACE

A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a space. Forced decimal point is disabled.

ASCII_DECIMAL_COMMA_NO_GROUPINGback to summary
public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_NO_GROUPING

A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts. Forced decimal point is disabled.

ASCII_DECIMAL_POINT_GROUP3_COMMAback to summary
public static final MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_COMMA

A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a comma. Forced decimal point is disabled.

ASCII_DECIMAL_POINT_GROUP3_SPACEback to summary
public static final MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_SPACE

A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a space. Forced decimal point is disabled.

ASCII_DECIMAL_POINT_NO_GROUPINGback to summary
public static final MoneyAmountStyle ASCII_DECIMAL_POINT_NO_GROUPING

A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts. Forced decimal point is disabled.

decimalPointCharacterback to summary
private final int decimalPointCharacter

The character used for the decimal point.

extendedGroupingSizeback to summary
private final int extendedGroupingSize

The size of each group.

forceDecimalPointback to summary
private final boolean forceDecimalPoint

Whether to always require the decimal point to be visible.

groupingCharacterback to summary
private final int groupingCharacter

The character used for grouping.

groupingSizeback to summary
private final int groupingSize

The size of each group.

groupingStyleback to summary
private final GroupingStyle groupingStyle

Whether to group or not.

LOCALIZED_CACHEback to summary
private static final ConcurrentMap<Locale, MoneyAmountStyle> LOCALIZED_CACHE

Cache of localized styles.

LOCALIZED_GROUPINGback to summary
public static final MoneyAmountStyle LOCALIZED_GROUPING

A style that will be filled in with localized values using the locale of the formatter. Grouping is enabled. Forced decimal point is disabled.

LOCALIZED_NO_GROUPINGback to summary
public static final MoneyAmountStyle LOCALIZED_NO_GROUPING

A style that will be filled in with localized values using the locale of the formatter. Grouping is disabled. Forced decimal point is disabled.

negativeCharacterback to summary
private final int negativeCharacter

The prefix string when the amount is negative.

positiveCharacterback to summary
private final int positiveCharacter

The character representing the positive sign.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

zeroCharacterback to summary
private final int zeroCharacter

The character defining zero, and thus the numbers zero to nine.

Constructor Detail

MoneyAmountStyleback to summary
private MoneyAmountStyle(int zeroCharacter, int positiveCharacter, int negativeCharacter, int decimalPointCharacter, GroupingStyle groupingStyle, int groupingCharacter, int groupingSize, int extendedGroupingSize, boolean forceDecimalPoint, boolean absValue)

Constructor, creating a new monetary instance.

Parameters
zeroCharacter:int

the zero character

positiveCharacter:int

the positive sign

negativeCharacter:int

the negative sign

decimalPointCharacter:int

the decimal point character

groupingStyle:GroupingStyle

the grouping style, not null

groupingCharacter:int

the grouping character

groupingSize:int

the grouping size

extendedGroupingSize:int

the extended grouping size

forceDecimalPoint:boolean

whether to always use the decimal point character

absValue:boolean

true to output the absolute value rather than the signed value

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Compares this style with another.

Parameters
other:Object

the other style, null returns false

Returns:boolean

true if equal

Annotations
@Override
getDecimalPointCharacterback to summary
public Character getDecimalPointCharacter()

Gets the character used for the decimal point.

Returns:Character

the decimal point character, null if to be determined by locale

getExtendedGroupingSizeback to summary
public Integer getExtendedGroupingSize()

Gets the size of each group, not typically used.

This is primarily used to enable the Indian Number System, where the group closest to the decimal point is of size 3 and other groups are of size 2. The extended grouping size is used for groups that are not next to the decimal point. The value zero is used to indicate that extended grouping is not needed.

Returns:Integer

the size of each group, null if to be determined by locale

getGroupingCharacterback to summary
public Character getGroupingCharacter()

Gets the character used to separate groups, typically thousands.

Returns:Character

the grouping character, null if to be determined by locale

getGroupingSizeback to summary
public Integer getGroupingSize()

Gets the size of each group, typically 3 for thousands.

Returns:Integer

the size of each group, null if to be determined by locale

getGroupingStyleback to summary
public GroupingStyle getGroupingStyle()

Gets the style of grouping required.

Returns:GroupingStyle

the grouping style, not null

getLocalizedStyleback to summary
private static MoneyAmountStyle getLocalizedStyle(Locale locale)

Gets the prototype localized style for the given locale.

This uses DecimalFormatSymbols and NumberFormat.

The method DecimalFormatSymbols.getInstance(locale) will be used in order to allow the use of locales defined as extensions.

Parameters
locale:Locale

the Locale used to get the correct DecimalFormatSymbols

Returns:MoneyAmountStyle

the symbols, never null

getNegativeSignCharacterback to summary
public Character getNegativeSignCharacter()

Gets the character used for the negative sign character.

The standard ASCII symbol is '-'.

Returns:Character

the format for negative amounts, null if to be determined by locale

getPositiveSignCharacterback to summary
public Character getPositiveSignCharacter()

Gets the character used for the positive sign character.

The standard ASCII symbol is '+'.

Returns:Character

the format for positive amounts, null if to be determined by locale

getZeroCharacterback to summary
public Character getZeroCharacter()

Gets the character used for zero, and defining the characters zero to nine.

The UTF-8 standard supports a number of different numeric scripts. Each script has the characters in order from zero to nine. This method returns the zero character, which therefore also defines one to nine.

Returns:Character

the zero character, null if to be determined by locale

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

A suitable hash code.

Returns:int

a hash code

Annotations
@Override
isAbsValueback to summary
public boolean isAbsValue()

Returns true if the absolute value setting.

If this is set to true, the absolute (unsigned) value will be output. If this is set to false, the signed value will be output. Note that when parsing, signs are accepted.

Returns:boolean

true to output the absolute value, false for the signed value

isForcedDecimalPointback to summary
public boolean isForcedDecimalPoint()

Gets whether to always use the decimal point, even if there is no fraction.

Returns:boolean

whether to force the decimal point on output

localizeback to summary
public MoneyAmountStyle localize(Locale locale)

Returns a MoneyAmountStyle instance configured for the specified locale.

This method will return a new instance where each field that was defined to be localized (by being set to null) is filled in. If this instance is fully defined (with all fields non-null), then this method has no effect. Once this method is called, no method will return null.

The settings for the locale are pulled from DecimalFormatSymbols and DecimalFormat.

Parameters
locale:Locale

the locale to use, not null

Returns:MoneyAmountStyle

the new instance for chaining, never null

ofback to summary
public static MoneyAmountStyle of(Locale locale)

Gets a localized style.

This creates a localized style for the specified locale. Grouping will be enabled, forced decimal point will be disabled, absolute values will be disabled.

Parameters
locale:Locale

the locale to use, not null

Returns:MoneyAmountStyle

the new instance, never null

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Gets a string summary of the style.

Returns:String

a string summarising the style, never null

Annotations
@Override
withAbsValueback to summary
public MoneyAmountStyle withAbsValue(boolean absValue)

Returns a copy of this style with the specified absolute value setting.

If this is set to true, the absolute (unsigned) value will be output. If this is set to false, the signed value will be output. Note that when parsing, signs are accepted.

Parameters
absValue:boolean

true to output the absolute value, false for the signed value

Returns:MoneyAmountStyle

the new instance for chaining, never null

withDecimalPointCharacterback to summary
public MoneyAmountStyle withDecimalPointCharacter(Character decimalPointCharacter)

Returns a copy of this style with the specified decimal point character.

For English, this is a dot.

Parameters
decimalPointCharacter:Character

the decimal point character, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null

withExtendedGroupingSizeback to summary
public MoneyAmountStyle withExtendedGroupingSize(Integer extendedGroupingSize)

Returns a copy of this style with the specified extended grouping size.

Parameters
extendedGroupingSize:Integer

the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null

Exceptions
IllegalArgumentException:
if the grouping size is zero or less
withForcedDecimalPointback to summary
public MoneyAmountStyle withForcedDecimalPoint(boolean forceDecimalPoint)

Returns a copy of this style with the specified decimal point setting.

Parameters
forceDecimalPoint:boolean

true to force the use of the decimal point, false to use it if required

Returns:MoneyAmountStyle

the new instance for chaining, never null

withGroupingCharacterback to summary
public MoneyAmountStyle withGroupingCharacter(Character groupingCharacter)

Returns a copy of this style with the specified grouping character.

For English, this is a comma.

Parameters
groupingCharacter:Character

the grouping character, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null

withGroupingSizeback to summary
public MoneyAmountStyle withGroupingSize(Integer groupingSize)

Returns a copy of this style with the specified grouping size.

Parameters
groupingSize:Integer

the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null

Exceptions
IllegalArgumentException:
if the grouping size is zero or less
withGroupingStyleback to summary
public MoneyAmountStyle withGroupingStyle(GroupingStyle groupingStyle)

Returns a copy of this style with the specified grouping setting.

Parameters
groupingStyle:GroupingStyle

the grouping style, not null

Returns:MoneyAmountStyle

the new instance for chaining, never null

withNegativeSignCharacterback to summary
public MoneyAmountStyle withNegativeSignCharacter(Character negativeCharacter)

Returns a copy of this style with the specified negative sign character.

The standard ASCII symbol is '-'.

Parameters
negativeCharacter:Character

the negative character, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null

withPositiveSignCharacterback to summary
public MoneyAmountStyle withPositiveSignCharacter(Character positiveCharacter)

Returns a copy of this style with the specified positive sign character.

The standard ASCII symbol is '+'.

Parameters
positiveCharacter:Character

the positive character, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null

withZeroCharacterback to summary
public MoneyAmountStyle withZeroCharacter(Character zeroCharacter)

Returns a copy of this style with the specified zero character.

The UTF-8 standard supports a number of different numeric scripts. Each script has the characters in order from zero to nine. This method sets the zero character, which therefore also defines one to nine.

For English, this is a '0'. Some other scripts use different characters for the numbers zero to nine.

Parameters
zeroCharacter:Character

the zero character, null if to be determined by locale

Returns:MoneyAmountStyle

the new instance for chaining, never null