[Tutor] Division doesn't work
Johan Geldenhuys
johan at accesstel.co.za
Thu Jan 18 13:16:36 CET 2007
Thanks at lot. Something as simple as that...
J
_____
From: Geoframer [mailto:geoframer at gmail.com]
Sent: 18 January 2007 02:10 PM
To: Johan Geldenhuys
Cc: tutor at python.org
Subject: Re: [Tutor] Division doesn't work
You assign s as an integer... it should be a float to get the right
result...
So either define s as
s = 14105.0
or as
s = float(14105)
it'll then result in the right answer :
In [17]: s=14105.0
In [18]: s/1024
Out[18]: 13.7744140625
In [19]: s = float(14105)
In [20]: s/1024
Out[20]: 13.7744140625
HTH - Geofram
On 1/18/07, Johan Geldenhuys <HYPERLINK
"mailto:johan at accesstel.co.za"johan at accesstel.co.za> wrote:
Hi all,
In my script I want to convert 14105 bytes to kilobytes and and this is what
I do:
>>> s = 14105
>>> print '%0.2f' % (s/1024)
13.00
This not correct and I don't know why. The answer is 13.77.
Any pointers please that would help my in the right direction?
Thanks
Johan
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16
04:36 PM
_______________________________________________
Tutor maillist - HYPERLINK "mailto:Tutor at python.org"Tutor at python.org
HYPERLINK "http://mail.python.org/mailman/listinfo/tutor"
\nhttp://mail.python.org/mailman/listinfo/tutor
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16
04:36 PM
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 2007/01/16
04:36 PM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070118/014b0252/attachment.html
More information about the Tutor
mailing list