Class PositiveDecimalColumn
java.lang.Object
io.github.kelsoncm.fwf.columns.AbstractColumn
io.github.kelsoncm.fwf.columns.PositiveIntegerColumn
io.github.kelsoncm.fwf.columns.PositiveDecimalColumn
Positive decimal column with a fixed number of decimal places, formatted with leading zeros.
-
Field Summary
FieldsFields inherited from class AbstractColumn
description, name, size, start -
Constructor Summary
ConstructorsConstructorDescriptionPositiveDecimalColumn(String name, int size) Constructs a newPositiveDecimalColumnwith a name and size, defaulting to 2 decimals.PositiveDecimalColumn(String name, int size, int decimals) Constructs a newPositiveDecimalColumnwith a name, size, and decimals.PositiveDecimalColumn(String name, int size, int decimals, String description) Constructs a newPositiveDecimalColumnwith a name, size, decimals, and description. -
Method Summary
Modifier and TypeMethodDescriptionintGets the number of implicit decimal places.Formats a non-negative Double/Float or null into a zero-padded string of exact column size.Converts a raw fixed-width zero-padded integer slice into a Double value with decimal precision.Methods inherited from class AbstractColumn
getDescription, getEnd, getName, getSize, getStart, setStart, validateToStrSize
-
Field Details
-
decimals
protected final int decimalsNumber of implicit decimal places.
-
-
Constructor Details
-
PositiveDecimalColumn
Constructs a newPositiveDecimalColumnwith a name, size, decimals, and description.- Parameters:
name- the column namesize- the total column size in charactersdecimals- number of implicit decimal places, must be > 0 and < sizedescription- human-readable description- Throws:
IllegalArgumentException- ifdecimals<= 0 orsize<=decimals
-
PositiveDecimalColumn
Constructs a newPositiveDecimalColumnwith a name, size, and decimals.- Parameters:
name- the column namesize- the total column size in charactersdecimals- number of implicit decimal places
-
PositiveDecimalColumn
Constructs a newPositiveDecimalColumnwith a name and size, defaulting to 2 decimals.- Parameters:
name- the column namesize- the total column size in characters
-
-
Method Details
-
getDecimals
public int getDecimals()Gets the number of implicit decimal places.- Returns:
- number of decimal places
-
toValue
Converts a raw fixed-width zero-padded integer slice into a Double value with decimal precision.- Overrides:
toValuein classPositiveIntegerColumn- Parameters:
slice- raw fixed-width substring- Returns:
- parsed Double value
- Throws:
IllegalArgumentException- ifsliceis not a valid positive decimal string
-
toStr
Formats a non-negative Double/Float or null into a zero-padded string of exact column size.- Overrides:
toStrin classPositiveIntegerColumn- Parameters:
value- Double, Float or null to format- Returns:
- zero-padded decimal string of size
AbstractColumn.getSize() - Throws:
IllegalArgumentException- ifvalueis negative or not a Double/Float
-