I have two integer values a
and b
, but I need their ratio in floating point. I know that a < b
and I want to calculate a / b
, so if I use integer division I'll always get 0 with a remainder of a
.
How can I force c
to be a floating point number in Python in the following?
c = a / b
If you want to use "true" (floating point) division by default, there is a command line flag:
There are some drawbacks (from the PEP):
You can learn more about the other flags values that change / warn-about the behavior of division by looking at the python man page.
For full details on division changes read: PEP 238 -- Changing the Division Operator