zut.numeric.parse_decimal

zut.numeric.parse_decimal(value: str | float | GoogleMoney | Decimal | None, *, required: Literal[True], max_decimals: int | None = None, reduce_decimals: int | Sequence[int] | bool = False, decimal_separator: Literal['.', ',', 'detect'] = '.') Decimal
zut.numeric.parse_decimal(value: str | float | GoogleMoney | Decimal | None, *, required: Literal[False] = False, max_decimals: int | None = None, reduce_decimals: int | Sequence[int] | bool = False, decimal_separator: Literal['.', ',', 'detect'] = '.') Decimal | None

Parse a decimal literal.

Parameters:
  • value – The value to convert.

  • max_decimals – Maximal number of decimal digits to use (the value will be rounded if necessary).

  • reduce_decimals – If set, reduce the number of decimal digits to the given number if this can be done without rounding (if set to True, try to reduce to 2 digits, otherwise to 5).

  • decimal_separator – Indicate if . or , is used as decimal separator, or detect to detect it (use with caution: might introduce errors if the values can have thousands separators).