Decimal Places Incorrect

T

Tom Haddon

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?

Thanks, Tom
 
C

Christopher Subich

Tom said:
> 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:15.05
 
D

Dan Bishop

Tom said:
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?

Because you forgot to use "from __future__ import division".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top