timetracker/common/utils.py

10 lines
289 B
Python
Raw Permalink Normal View History

2023-11-09 09:06:14 +00:00
def safe_division(numerator: int | float, denominator: int | float) -> int | float:
"""
Divides without triggering division by zero exception.
Returns 0 if denominator is 0.
"""
try:
return numerator / denominator
except ZeroDivisionError:
return 0