Package net.sf.basedb.util.formatter
Class NumberFormatter
- java.lang.Object
-
- net.sf.basedb.util.formatter.NumberFormatter
-
- All Implemented Interfaces:
ExcelFormatter<Number,Number>
,Formatter<Number>
- Direct Known Subclasses:
AdaptiveNumberFormatter
public class NumberFormatter extends Object implements Formatter<Number>, ExcelFormatter<Number,Number>
Formats a number for output on a web page.- Version:
- 2.2
- Author:
- nicklas
- Last modified
- $Date: 2019-03-13 14:37:22 +0100 (ons, 13 mars 2019) $
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
doubleValues
private int
numDecimals
-
Constructor Summary
Constructors Constructor Description NumberFormatter(int numDecimals, 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.Number
parseString(String value)
Parse a string and return a value of the correct type.ExcelValue<Number>
toExcelValue(Number value)
Convert and format the given value to an Excel value.
-
-
-
Constructor Detail
-
NumberFormatter
public NumberFormatter(int numDecimals, boolean doubleValues)
Create a new number formatter.- Parameters:
numDecimals
- The number of decimals to display, or a negative value to display all decimalsdoubleValues
- If theparseString(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.
-
parseString
public Number parseString(String value)
Description copied from interface:Formatter
Parse a string and return a value of the correct type. A null input string should (unless otherwise documented by a specific formatter implementation) be allowed and may return null or any other "default" value.- Specified by:
parseString
in interfaceFormatter<Number>
- Parameters:
value
- The string to parse- Returns:
- An object
-
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>
- Since:
- 3.15
-
-