Getting ZeroDivisionError when NOT dividing by zero

Question:

I have a flask app that returns a ZeroDivisionError. The numerator is zero but the denominator is not and the operation should return zero.

Using the Jinja2 debugger, I can query the variables to see that no division by zero is actually happening. See screenshot:

Does anybody know why this is happening?

Asked By: Amish

||

Answers:

Please remember about operator precedence. Your calculation seems to do 0 / 0 + 1529.657.... Division 0 / 0 is being done first, and so your operation results in ZeroDivisionError

To solve your problem, put everything behind division sign in parentheses, to make it 0 / (0 + 1529.657...)

Answered By: BlackAnubis7
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.