What's the Best Option for Integer Division

Întrebare What's the Best Option for Integer Division

  • 18 august 2011 19:08
     
     

    Integer division in python pre-3.0 is annoying in that integer division returns the floor integer, not a float. For example 1/2 = 0

    The way around that is to cast one integer to a float via float() or appending .0 i.e. 1.0/2 = 0.5

    That's a bit of a pain, and CPython offers from __futures__ import division, but IronPython doesn't have that. Is there any other nicer way to get integer division less kludgy? Will python 3.0 syle division be supported in the future.


    Peter Newhook SharePoint posts on my blog

Toate mesajele

  • 4 septembrie 2011 23:42
    Moderator
     
     
    Sorry, there's no nice way around this, since we stick to the Python 2.6 standard. In my code, I convert to a float. --- John