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:
- 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$
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
precision
private final int precision
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 the NumberFormatter.parseString(String)
should return double
or float values- See Also:
Values.formatNumber(Float, int)
format
public String format(Number value)
- Description copied from interface:
Formatter
- Format a value by converting it to a string.
- Specified by:
format
in interface Formatter<Number>
- Overrides:
format
in class NumberFormatter
- Parameters:
value
- The value to format
- Returns:
- A formatted string