Class FmtNumber
java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.FmtNumber
- All Implemented Interfaces:
CellProcessor, DoubleCellProcessor, LongCellProcessor
public class FmtNumber
extends CellProcessorAdaptor
implements DoubleCellProcessor, LongCellProcessor
Converts a double into a formatted string using the
If you want to convert from a String to a decimal, use the
DecimalFormat class and the default locale. This is
useful, when you need to show numbers with a specific number of digits.
Please be aware that the constructors that use DecimalFormat are not thread-safe, so it is generally better to use the constructors that accept a date format String.
In the format string, the following characters are defined as :
0 - means Digit # - means Digit, zero shows as absent (works only as zero padding on the right hand side of the number) . - means Decimal separator or monetary decimal separator - - means Minus sign , - means Grouping separator
If you want to convert from a String to a decimal, use the
ParseDouble or ParseBigDecimal processor.- Since:
- 1.50
- Author:
- Kasper B. Graversen, James Bassett
-
Field Summary
Fields inherited from class CellProcessorAdaptor
next -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format String.FmtNumber(String decimalFormat, StringCellProcessor next) Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format String, then calls the next processor in the chain.FmtNumber(DecimalFormat formatter) Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format.FmtNumber(DecimalFormat formatter, StringCellProcessor next) Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format, then calls the next processor in the chain. -
Method Summary
Modifier and TypeMethodDescriptionexecute(Object value, CsvContext context) This method is invoked by the framework when the processor needs to process data or check constraints.Methods inherited from class CellProcessorAdaptor
toString, validateInputNotNull
-
Constructor Details
-
FmtNumber
Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format String. This constructor is thread-safe.- Parameters:
decimalFormat- the decimal format String (seeDecimalFormat)- Throws:
NullPointerException- if decimalFormat is null
-
FmtNumber
Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format String, then calls the next processor in the chain. This constructor is thread-safe.- Parameters:
decimalFormat- the decimal format String (seeDecimalFormat)next- the next processor in the chain- Throws:
NullPointerException- if decimalFormat or next is null
-
FmtNumber
Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format. This constructor is not thread-safe.- Parameters:
formatter- the DecimalFormat- Throws:
NullPointerException- if formatter is null
-
FmtNumber
Constructs a new FmtNumber processor, which converts a double into a formatted string using the supplied decimal format, then calls the next processor in the chain. This constructor is not thread-safe.- Parameters:
formatter- the DecimalFormatnext- the next processor in the chain- Throws:
NullPointerException- if formatter or next is null
-
-
Method Details
-
execute
This method is invoked by the framework when the processor needs to process data or check constraints.- Specified by:
executein interfaceCellProcessor- Parameters:
value- the value to be processedcontext- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException- if value is null or not a Number, or if an invalid decimalFormat String was supplied
-