[Tutor] float question
Pujo Aji
ajikoe at gmail.com
Tue Dec 20 09:59:08 CET 2005
Th format %x1.x2f
where x1 is the total space and x2 is decimal digit place.
If your data is longer than the specified x1 and x2.
the data rules.
Look at 3.14 takes 4 places total
# 4 places rules
>>> '%3.2f' % 3.14
'3.14'
# perfect
>>> '%4.2f' % 3.14
'3.14'
# try this
>>> '%5.2f' % 3.14
' 3.14'
Cheers,
pujo
On 12/20/05, linda.s <samrobertsmith at gmail.com> wrote:
>
> On 12/20/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> >
> >
> > On Mon, 19 Dec 2005, linda.s wrote:
> >
> > > what does 2 mean in %2.4f ?
> >
> > Hello,
> >
> > It's a "minimal field width" modifier, according to:
> >
> > http://docs.python.org/lib/typesseq-strings.html
> >
> >
> > Let's try experimenting with it.
> >
> > ######
> > >>> '%20f' % 3.14
> > ' 3.140000'
> > >>> '%20.2f' % 3.14
> > ' 3.14'
> > ######
> >
> >
> > Does this make sense? If you have more questions, please feel free to
> > ask.
>
> Danny,
> Thanks. Still confused. I changed the code a little.
> >>> '%3.2f' % 3.14
> '3.14'
> >>> '%4.2f' % 3.14
> '3.14'
> there is no difference in the above two codes. so what does 3 and 4 mean?
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051220/a13311c5/attachment.htm
More information about the Tutor
mailing list