From b85de39cd765164d5a31836cb7ca106ad6e328a7 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 4 Sep 2024 20:16:15 +0200 Subject: Switch to decimal.Decimal for money Floating point data types are not suitable to represent money since rounding issues will sum up. --- finance/income.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'finance/income.py') diff --git a/finance/income.py b/finance/income.py index 94759ff..8d775cb 100644 --- a/finance/income.py +++ b/finance/income.py @@ -1,17 +1,18 @@ import dataclasses from datetime import datetime +from decimal import Decimal @dataclasses.dataclass(kw_only=True, frozen=True) class Income: """Income models financial income paid on the first day of a month""" - amount: float + amount: Decimal - def integrate(self, start: datetime, end: datetime) -> float: + def integrate(self, start: datetime, end: datetime) -> Decimal: """Integrate the income from a start to an end date""" - retval = 0.0 + retval = Decimal(0.0) current = datetime(start.year, start.month, 1) -- cgit v1.2.3-70-g09d2