aeat.core.decimal._format module

Canonical Decimal formatting helpers for the AEAT domain.

Consolidates the four independent _format_decimal copies that previously lived in _censo_live, _reconcile, _projection, and _translator. All call-sites must import from this module.

format_decimal(value, *, normalize=False, none_value=None)[source]

Render value in fixed-point notation (no scientific notation).

Parameters:
  • value (Decimal | None) – The decimal to format. Pass None only when none_value is also provided.

  • normalize (bool) – When True call Decimal.normalize() before formatting, which strips trailing zeros (e.g. Decimal("1.50")"1.5").

  • none_value (str | None) – String to return when value is None. When None (the default), a None value raises DecimalFormatError.

Return type:

str

Returns:

Fixed-point string representation of value.

Raises:

DecimalFormatError – When value is None and none_value was not provided.

Examples

>>> from decimal import Decimal
>>> format_decimal(Decimal("12.34"))
'12.34'
>>> format_decimal(Decimal("1.50"), normalize=True)
'1.5'
>>> format_decimal(None, none_value="0")
'0'