[Tutor] floats acting like integers???
dyoo at hkn.eecs.berkeley.edu
Tue Jul 27 02:38:49 CEST 2004
On Mon, 26 Jul 2004, Hee-Seng Kye wrote:
> Hi. To get floats for divisions, either the number you are dividing or
> being divided should be a floating point.
> >>> a = 1.0 / 7 # or a = 1 / 7.0
> >>> a
> >>> print a
Just as a side note: this does come up often enough as an issue that
there's a long-term plan to change the division operator:
The default is still the old behavior (int divided by int -> int). But
it's possible to enable 'True Division' mode by putting:
from __future__ import division
at the very top of your program.
Good luck to you!
More information about the Tutor