from decimal import Decimal
class Money:
def __init__(self, amount: Decimal, currency: str, precision: int = 2):
self.amount = amount
self.currency = currency
self.precision = precision
def __str__(self):
return f"{self.amount:.{self.precision}f} {self.currency}"
def __repr__(self):
return f"Money({self.amount!r}, {self.currency!r}, {self.precision!r})"
money = Money(1234.123, "Pln", 3)
print(money)
money = Money(123.123, "Pln")
print(money)
money = Money(1234.123, "Pln", 4)
print(money)