Negativ nearest interger?

joni joni8135 at gmail.com
Thu Sep 22 16:13:54 CEST 2011


On Sep 22, 1:44 pm, Jussi Piitulainen <jpiit... at ling.helsinki.fi>
wrote:
> joni writes:
> > Have a simple question in the Integer calculator in Python 2.65 and
> > also 2.7..
>
> > The consol showing:
>
> > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
> ...
> > >>> -7/3
> > -3
>
> > -3 are more wrong than -2. Negativ number seems not to round to
> > nearest interger, but the integer UNDER the anwser!! Or?
>
> > Why?
>
> It simply does not round to the nearest integer. It floors. This has
> nicer mathematical properties. In particular, it allows the remainder
> (notated as "per cent") operation (n % m) to return a number that
> differs from n by a multiple of m ("is congruent to n modulo m").
> These two operations go together.

Thanx. See if I can understand it.... /Cheers



More information about the Python-list mailing list