3.2.4: 2013-12-06

net.sf.basedb.util.formatter
Class AdaptiveNumberFormatter

java.lang.Object
  extended by net.sf.basedb.util.formatter.NumberFormatter
      extended by 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$

Field Summary
private  int precision
           
 
Constructor Summary
AdaptiveNumberFormatter(int precision, boolean doubleValues)
          Create a new number formatter.
 
Method Summary
 String format(Number value)
          Format a value by converting it to a string.
 
Methods inherited from class net.sf.basedb.util.formatter.NumberFormatter
parseString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

precision

private final int precision
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 decimals
doubleValues - If the NumberFormatter.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 interface Formatter<Number>
Overrides:
format in class NumberFormatter
Parameters:
value - The value to format
Returns:
A formatted string

3.2.4: 2013-12-06