Class: PositiveDecimalColumn

PositiveDecimalColumn(name, size, decimalsopt, descriptionopt)

Positive decimal column formatted with fixed decimal places and leading zeros. Represents fixed-point numbers without explicit decimal points (e.g. 125050 with 2 decimals = 1250.50).

Constructor

new PositiveDecimalColumn(name, size, decimalsopt, descriptionopt)

Creates an instance of PositiveDecimalColumn.
Parameters:
Name Type Attributes Default Description
name string Column identifier name.
size number Total column size width, must be > decimals.
decimals number <optional>
2 Number of implicit decimal places, must be > 0.
description string | null <optional>
null Column description.
Source:
Throws:
If decimals is <= 0 or size is <= decimals.
Type
Error
Example
const col = new PositiveDecimalColumn('amount', 9, 2, 'Total Amount');
col.toValue('000125050'); // 1250.5
col.toStr(1250.50); // '000125050'

Extends

Classes

PositiveDecimalColumn

Members

decimals :number

Implicit decimal places.
Type:
  • number
Source:

description :string

Description of the column.
Type:
  • string
Overrides:
Source:

end :number

1-indexed end position of the column within a row line.
Type:
  • number
Overrides:
Source:

name :string

Name of the column.
Type:
  • string
Overrides:
Source:

size :number

Character width of the column.
Type:
  • number
Overrides:
Source:

start :number|null

1-indexed start position of the column within a row line.
Type:
  • number | null
Overrides:
Source:

Methods

toStr(value) → {string}

Serializes a decimal float number into a zero-padded fixed-width string.
Parameters:
Name Type Description
value number | null Decimal float number. Null/undefined serializes to zeros.
Overrides:
Source:
Throws:
If value is not a non-negative number.
Type
Error
Returns:
Zero-padded fixed-width string representation.
Type
string

toValue(slice) → {number}

Converts raw string slice from file to a float number.
Parameters:
Name Type Description
slice string Raw fixed-width digit string slice.
Overrides:
Source:
Throws:
If slice cannot be converted to a positive decimal.
Type
Error
Returns:
Parsed decimal float value.
Type
number

validateToStrSize(value) → {string}

Validates that a formatted string representation matches the required column size.
Parameters:
Name Type Description
value string The formatted string to validate.
Overrides:
Source:
Throws:
If formatted string length does not equal column size.
Type
Error
Returns:
The validated string.
Type
string