[Zope] Weird interaction between int() and DateTime.timeTime

Jeff K. Hoffman jeff.hoffman@goingv.com
Thu, 25 May 2000 14:57:56 -0400 (EDT)


On Thu, 25 May 2000, Chris Withers wrote:

> "Jeff K. Hoffman" wrote:
> >   Python 1.5.2 (#3, Mar  8 2000, 16:34:52) [C] on sunos5
> >   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >   >>>
> >   >>> f = 1.999999999999
> >   >>> f
> >   2.0
> >   >>> int(f)
> >   1
> >   >>>
> 
> > the int() function takes a different code path and returns 1, correctly.
> 
> Forgive my ignorance, but in what way is 1 correct here? Surely 2 is the
> what should be returned?!

int() disregards everything after the decimal.

  >>> int(1.25)
  1
  >>> int(1.5)
  1
  >>> int(1.75)
  1
  >>> int(1.999999999999)
  1
  >>> int(2)
  2

The problem comes in when you consider that the string representation
functions (and thus, print) do not behave in the same way.

  >>> print 1.25
  1.25
  >>> print 1.5
  1.5
  >>> print 1.75
  1.75
  >>> print 1.9    
  1.9
  >>> print 1.999
  1.999
  >>> print 1.99999
  1.99999
  >>> print 1.9999999
  1.9999999
  >>> print 1.999999999
  1.999999999
  >>> print 1.99999999999
  1.99999999999
  >>> print 1.9999999999999
  2.0

> Chris

--Jeff

---
Jeff K. Hoffman                               704.849.0731 x108
Chief Technology Officer                      mailto:jeff.hoffman@goingv.com
Going Virtual, L.L.C.                         http://www.goingv.com/