Class SimpleNumberFormatter
java.lang.Object
me.datafox.dfxengine.text.formatter.SimpleNumberFormatter
- All Implemented Interfaces:
Comparable<Handled>,Handled,NumberFormatter
A
NumberFormatter that formats a number in a natural form. The precision of the number can be configured with
PRECISION, and the minimum absolute exponent when a NumberSuffixFormatter will be used can be
configured with MIN_EXPONENT. The minimum exponent must be smaller than or equal to the precision. Any
trailing zeros in the decimal part of the number can be stripped, configured by STRIP_ZEROS.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConfigurationKey<Integer> Minimum absolute exponent to be formatted with a suffix.static final ConfigurationKey<Integer> Precision, equivalent toMathContext.getPrecision().static final ConfigurationKey<Boolean> Iftrue, the number will be stripped of any trailing zeros in the decimal part of the number before formatting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat(BigDecimal number, TextFactory factory, TextConfiguration configuration)
-
Field Details
-
PRECISION
Precision, equivalent toMathContext.getPrecision(). The default value is6. -
MIN_EXPONENT
Minimum absolute exponent to be formatted with a suffix. It must be smaller than or equal toPRECISION. The default value is3. -
STRIP_ZEROS
Iftrue, the number will be stripped of any trailing zeros in the decimal part of the number before formatting. The default value istrue.
-
-
Constructor Details
-
SimpleNumberFormatter
- Parameters:
logger-Loggerfor this formatterhandles-TextHandlesto be used for this formatter'sHandle
-
-
Method Details
-
format
- Specified by:
formatin interfaceNumberFormatter- Parameters:
number- number to be formatterfactory-TextFactoryfor formattingconfiguration-TextConfigurationfor formatting- Returns:
Stringrepresentation of the number- Throws:
TextConfigurationException- if theTextConfigurationis not valid for this formatter
-