[omaha] Tutorial: integer division
Jay Hannah
jay at jays.net
Sat Dec 1 15:26:36 CET 2007
This surprised me:
http://docs.python.org/tut/node5.html
>>> # Integer division returns the floor:
... 7/3
2
So I tried my own:
>>> x = 7
>>> y = 3
>>> x / y
2
This strikes me as very counter-intuitive... How do you avoid getting
burned by this?
Forcing a decimal point into the mix does what I expect:
>>> x = 7.0
>>> y = 3
>>> x / y
2.3333333333333335
But how do I systematically enforce floating point division into my
applications?
Thanks,
j
didn't even mention Perl. Aren't you proud of me? -grin-
More information about the Omaha
mailing list