ROUNDING???
Asun Friere
afriere at yahoo.co.uk
Tue Feb 19 00:08:19 EST 2008
On Feb 19, 2:05 pm, 7stud <bbxx789_0... at yahoo.com> wrote:
> An integer divided by an integer produces an integer. In computer
> programming, that's called 'integer arithmetic', and any fractional
> part of the result is chopped off(not rounded).
In case you care, the "chopped off" bit is given by the modulo
operator '%'. So integer division x/y is really like the everyday y
goes into x, p times, remainder q, for example:
>>> 10/3, 10%3
(3, 1)
> If your arithmetic
> involves at least one float, then you will get a float as an asnwer:
>
> print 255/494
> print 255.0/494
> print (255 * 1.0)/494
or indeed "print float(255)/494"
More information about the Python-list
mailing list