Skip to content

Commit

Permalink
Avoid zero division
Browse files Browse the repository at this point in the history
  • Loading branch information
hfaran committed Dec 18, 2017
1 parent a84aa30 commit cb75b21
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions progressive/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ def draw(self, value, newline=True, flush=True):
# the terminal since the code is mostly written dynamically
# and many attributes and dynamically calculated properties.
self._measure_terminal()

amount_complete = value / self.max_value

# To avoid zero division, set amount_complete to 100% if max_value has been stupidly set to 0
amount_complete = 1.0 if self.max_value == 0 else value / self.max_value
fill_amount = int(floor(amount_complete * self.max_width))
empty_amount = self.max_width - fill_amount

Expand Down

0 comments on commit cb75b21

Please sign in to comment.