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. PassNoneonly when none_value is also provided.normalize (
bool) – WhenTruecallDecimal.normalize()before formatting, which strips trailing zeros (e.g.Decimal("1.50")→"1.5").none_value (
str|None) – String to return when value isNone. WhenNone(the default), aNonevalue raisesDecimalFormatError.
- Return type:
- Returns:
Fixed-point string representation of value.
- Raises:
DecimalFormatError – When value is
Noneand 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'