docling icon indicating copy to clipboard operation
docling copied to clipboard

EBCDIC implied-decimal scaling silently rounds numeric fields

Open WitBlue6 opened this issue 1 month ago • 0 comments

Bug

EBCDIC numeric fields with an implied decimal scale are rounded while being decoded. _FieldDecoder.decode() calls Decimal(value).scaleb(-field.scale), an arithmetic operation governed by the caller's decimal context. The default precision (28) silently changes valid 31-digit COMP-3/display values; reducing the context precision also changes smaller fields. Decoding a copybook should preserve the encoded digits.

For example, with the default context, coefficient 1234567890123456789012345678901 and scale=2 becomes 12345678901234567890123456790 instead of 12345678901234567890123456789.01. This is visible both in table cells and Markdown export.

Locally reproduced on current main (docling-slim 2.137.0, Python 3.10.17), via the real DocumentConverter using packed decimal, zoned decimal, signed and unsigned binary fields. Regression tests fail for all four types at precision 28 and precision 6 (8 failures). Searched prior EBCDIC decimal/precision PRs: #4296 fixed fixed-point formatting, but leaves arithmetic rounding unchanged.

Proposed fix: construct a Decimal directly from the encoded coefficient and scale, avoiding context-dependent arithmetic. Preserve the existing fixed-point formatting and do not change global decimal settings. Found by inspection and local reproduction with AI assistance, not a claimed production incident.

WitBlue6 avatar Oct 11 '26 04:10 WitBlue6