Decimal Places Incorrect
Christopher Subich
spam.csubich+block at block.subich.spam.com
Wed Jun 8 20:56:34 EDT 2005
Tom Haddon wrote:
> Hi Folks,
>
> When I run:
>
> print "%0.2f" % ((16160698368/1024/1024/1024),)
>
> I get 15.00
>
> I should be getting 15.05. Can anyone tell me why I'm not?
Short answer: Integer division.
Long answer: Integer division.
16160698368/1024 = 15781932L
15781932L/1024 = 15412
15412/1024 = 15
Fix:
>>> print "%.02f" % (float(16160698368)/1024/1024/1024,)
15.05
More information about the Python-list
mailing list