Skip to content

Commit

Permalink
Fix behavior when the specified number of decimals is not high enough…
Browse files Browse the repository at this point in the history
… to display the value
  • Loading branch information
paul019 committed Mar 19, 2024
1 parent 24cb501 commit 4377ed8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/application/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def get_first_digit(cls, value: Decimal) -> int:
@classmethod
def round_to_n_decimal_places(cls, value: Decimal, n: int) -> str:
try:
decimal_value = value.quantize(Decimal(f"1.{'0' * abs(n)}"))
return f"{decimal_value:.{abs(n)}f}"
decimal_value = value.quantize(Decimal(f"1.{'0' * n}"))
return f"{decimal_value:.{n}f}"
except decimal.InvalidOperation as exc:
raise ValueError(
"Your precision is set too low to be able to process the given value without any"
Expand Down
4 changes: 4 additions & 0 deletions src/domain/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def __init__(self, value: Decimal, min_exponent: Union[int, None] = None):

def set_min_exponent(self, min_exponent: int):
self._min_exponent = min_exponent
if min_exponent > self._max_exponent:
self._max_exponent = min_exponent
# TODO: Raise a warning here? However, a warning should be raised on application level
# rather than here.

def get_min_exponent(self) -> int:
return self._min_exponent
Expand Down

0 comments on commit 4377ed8

Please sign in to comment.