Verified Commit 48833571 authored by Jakob Moser's avatar Jakob Moser
Browse files

Create amount parsing function

parent c526c319
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
from decimal import Decimal


def parse_euro_amount(amount_str: str) -> Decimal:
    """Parse a currency amount in Euro specified as string, and return its value as a Decimal."""

    # TODO Improve this clunky heuristic
    amount_without_sign = amount_str.removesuffix("").strip()
    if "," in amount_without_sign:
        return Decimal(amount_without_sign.replace(".", "").replace(",", "."))
    else:
        return Decimal(amount_without_sign.replace(",", ""))