ROUNDING???

Jeff Schwab jeff at schwabcenter.com
Tue Feb 19 04:12:38 CET 2008


7stud wrote:
> On Feb 18, 7:57 pm, katie smith <iceboy... at yahoo.com> wrote:
>> in python im doing the problem 255/494
>>
>> it keeps giving me 0 instead of .51....
>> what am i doing wrong?
>>
>> please help me I have been looking for hours
>>
>>       ___________________________________________________________________________ _________
>> Never miss a thing.  Make Yahoo your home page.http://www.yahoo.com/r/hs
> 
> 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).  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
> 
> --output:--
> 0
> 0.516194331984
> 0.516194331984

Not that this behavior is expected to change in the future, such that 
255 / 494 will actually perform floating-point division.  The way to 
achieve flooring division will be 255 // 494.



More information about the Python-list mailing list