Home > Blockchain >  Getting ZeroDivisionError when NOT dividing by zero
Getting ZeroDivisionError when NOT dividing by zero

Time:07-11

I have a flask app which returns a ZeroDivisionError. Numerator is zero but denominator is not and the operation should return zero.

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

Does anybody know why this is happening ?

CodePudding user response:

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...)

  • Related