[Tutor] floats

Walter Prins wprins at gmail.com
Tue Jun 7 22:31:27 CEST 2011


Hello Michael

On 7 June 2011 21:10, Michael bridges <micha_el2003 at yahoo.com> wrote:

> ok, will attempt to clarify.
> i want to out put of two numbers [int or float or anything] to be x.xx not
> x.x.
> i want two numbers after the decimal not one.
>
> Alan's already given you exactly the correct answer.  Have you tried his
suggestions?  What did you not understand or what problems did you run into?

Here's a little example from an interactive Python interpreter session which
shows you how you can play with these concepts to help clarify your
understanding:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on
win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> res = 10/float(20)
>>> res
0.5
>>> "%f" % res
'0.500000'
>>> "%7.3f" % res
'  0.500'
>>> str = "%6e" % res
>>> str
'5.000000e-01'
>>> print str
5.000000e-01
>>>

Regards,

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110607/de9dd55a/attachment.html>


More information about the Tutor mailing list