Skip to content

Commit

Permalink
Another fix for generating decimal examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-koziol-iteo committed Mar 7, 2024
1 parent 2516007 commit e6e012b
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 e6e012b

Please sign in to comment.