Canonical way to ensure float point division across py2 and py3?

24 Views Asked by At

I have a function that needs to support both py2 and py3, unfortunately.

Currently, there's a division op:

n = a / b

a and b are usually whole numbers, but represented as floats, but from what I can see there's no guarantee that either is a float, so the division could result in different behavior in py2 vs py3.

I plan on changing it to:

n = float(a) / b

which should guarantee float division in both versions. Is this the canonical way of doing this in python or is there a more accepted approach?

0

There are 0 best solutions below