Package net.sf.basedb.util.formatter
Class AdaptiveNumberFormatter
java.lang.Object
net.sf.basedb.util.formatter.NumberFormatter
net.sf.basedb.util.formatter.AdaptiveNumberFormatter
- All Implemented Interfaces:
ExcelFormatter<Number,
,Number> Formatter<Number>
Formats a number for output on a web page adapting thwe number of
decimals depending on the order of magnitude of the value. The precision
value is defined to be the number of decimals to use for values
between 1 and 10 (not inclusive). The number of decimals are then
increase or decreased for each order of magnitude that the value
get smaller or larger.
- Since:
- 3.2.2
- Author:
- nicklas
- Last modified
- $Date$
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAdaptiveNumberFormatter
(int precision, boolean doubleValues) Create a new number formatter. -
Method Summary
Modifier and TypeMethodDescriptionFormat a value by converting it to a string.private int
getNumDecimals
(Number value) toExcelValue
(Number value) Convert and format the given value to an Excel value.Methods inherited from class net.sf.basedb.util.formatter.NumberFormatter
parseString
-
Field Details
-
precision
private final int precision
-
-
Constructor Details
-
AdaptiveNumberFormatter
public AdaptiveNumberFormatter(int precision, boolean doubleValues) Create a new number formatter.- Parameters:
precision
- The number of decimals to display for values between 1 and 10 (for lower and higher values the number of decimals is adjusted), or a negative value to display all decimalsdoubleValues
- If theNumberFormatter.parseString(String)
should return double or float values- See Also:
-
-
Method Details
-
format
Description copied from interface:Formatter
Format a value by converting it to a string.- Specified by:
format
in interfaceFormatter<Number>
- Overrides:
format
in classNumberFormatter
- Parameters:
value
- The value to format- Returns:
- A formatted string
-
toExcelValue
Description copied from interface:ExcelFormatter
Convert and format the given value to an Excel value. If the value is null the implementation may return null to create an empty cell or it may return another non-null value.- Specified by:
toExcelValue
in interfaceExcelFormatter<Number,
Number> - Overrides:
toExcelValue
in classNumberFormatter
- Since:
- 3.15
-
getNumDecimals
-