Skip to content

Commit

Permalink
Merge pull request #56 from Iteo/another-decimal-example-fix
Browse files Browse the repository at this point in the history
Another fix for generating decimal examples
  • Loading branch information
marcin-koziol-iteo authored Mar 7, 2024
2 parents 2516007 + e6e012b commit 901e36e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions audoma/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ def generate_value(self) -> float:
Random value between min_value and max_value
"""
min_val = float(getattr(self.field, "min_value", 1) or 1)
max_val = float(getattr(self.field, "max_value", 1000) or 1000)
decimal_places = getattr(self.field, "decimal_places", None)
decimal_places = getattr(self.field, "decimal_places", 0) or 0
max_digits = getattr(self.field, "max_digits", 4) or 4
max_val_fallback = 10 * (max_digits - decimal_places) - 1
max_val = float(
getattr(self.field, "max_value", max_val_fallback) or max_val_fallback
)

if decimal_places:
fmt = f".{decimal_places}f"
return Decimal(f"{(max_val):{fmt}}")
Expand Down

0 comments on commit 901e36e

Please sign in to comment.