spring-framework / org.springframework.format.annotation / NumberFormat

NumberFormat

@Target([AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.ANNOTATION_CLASS]) class NumberFormat

Declares that a field or method parameter should be formatted as a number.

Supports formatting by style or custom pattern string. Can be applied to any JDK java.lang.Number type.

For style-based formatting, set the #style attribute to be the desired Style. For custom formatting, set the #pattern attribute to be the number pattern, such as #, ###.##.

Each attribute is mutually exclusive, so only set one attribute per annotation instance (the one most convenient one for your formatting needs). When the #pattern attribute is specified, it takes precedence over the #style attribute. When no annotation attributes are specified, the default format applied is style-based for either number of currency, depending on the annotated field or method parameter type.

Author
Keith Donald

Author
Juergen Hoeller

Since
3.0

See Also
java.text.NumberFormat

Constructors

<init>

NumberFormat(style: Style, pattern: String)

Declares that a field or method parameter should be formatted as a number.

Supports formatting by style or custom pattern string. Can be applied to any JDK java.lang.Number type.

For style-based formatting, set the #style attribute to be the desired Style. For custom formatting, set the #pattern attribute to be the number pattern, such as #, ###.##.

Each attribute is mutually exclusive, so only set one attribute per annotation instance (the one most convenient one for your formatting needs). When the #pattern attribute is specified, it takes precedence over the #style attribute. When no annotation attributes are specified, the default format applied is style-based for either number of currency, depending on the annotated field or method parameter type.

Properties

pattern

val pattern: String

The custom pattern to use to format the field.

Defaults to empty String, indicating no custom pattern String has been specified. Set this attribute when you wish to format your field in accordance with a custom number pattern not represented by a style.

style

val style: Style

The style pattern to use to format the field.

Defaults to Style#DEFAULT for general-purpose number formatting for most annotated types, except for money types which default to currency formatting. Set this attribute when you wish to format your field in accordance with a common style other than the default style.