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>
public class AdaptiveNumberFormatter extends NumberFormatter
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
Fields Modifier and Type Field Description private int
precision
-
Constructor Summary
Constructors Constructor Description AdaptiveNumberFormatter(int precision, boolean doubleValues)
Create a new number formatter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(Number value)
Format a value by converting it to a string.private int
getNumDecimals(Number value)
ExcelValue<Number>
toExcelValue(Number value)
Convert and format the given value to an Excel value.-
Methods inherited from class net.sf.basedb.util.formatter.NumberFormatter
parseString
-
-
-
-
Constructor Detail
-
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:
Values.formatNumber(Float, int)
-
-
Method Detail
-
format
public String format(Number value)
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
public ExcelValue<Number> toExcelValue(Number value)
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
private int getNumDecimals(Number value)
-
-