Pardon my ignorance, data conversion

Michael P. Reilly arcege at shore.net
Tue Jan 18 20:14:43 EST 2000


Fran?ois Pinard <pinard at iro.umontreal.ca> wrote:
: aahz at netcom.com (Aahz Maruch) writes:

:> Robert W. McGwier <rwmcgwier at home.com> wrote:

:> >I need to do the simple task of taking a nonnegative floating point
:> >variable and taking its integer part and storing it in an integer.
:> >Damned if I can find how to do it.

:> import math
:> i = int(math.floor(real))

: Would not a mere:

:    integer_value = int(real_value)

: be sufficient?

Floor does funny things to negative numbers.

Python 1.5.2 (#2, May 11 1999, 17:14:37)  [GCC 2.7.2.1] on freebsd3
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> int(4.5)
4
>>> int(-3.4)
-3
>>> int(-4.5)
-4
>>> from math import floor
>>> int(floor(-3.4))
-4
>>> int(floor(-4.5))
-5
>>>

  -Arcege




More information about the Python-list mailing list