> -----Original Message----- > From: Kent Johnson [mailto:[EMAIL PROTECTED] > Sent: Monday, March 19, 2007 12:59 PM > To: Carroll, Barry > Cc: tutor@python.org > Subject: Re: [Tutor] Making table > > Carroll, Barry wrote: > >> -----Original Message----- > >> Date: Mon, 19 Mar 2007 11:53:06 -0400 > >> From: Kent Johnson <[EMAIL PROTECTED]> > > >> Most string formatting conversions allow you to specify a width > >> directly. For example, > >> In [61]: value = 3.45678 > >> In [63]: "%10.3f" % value > >> Out[63]: ' 3.457' > >> > >> Kent > >> > > What if one wished to align the values in each column at the decimal > > point? Is there a simple means to do this in Python, or would one need > > to write a new function? > > If you specify the number of digits after the decimal point, that number > of digits will always be given, so columns will line up: > In [86]: '%10.3f' % 1.2 > Out[86]: ' 1.200' > In [87]: '%10.3f' % 1.23456 > Out[87]: ' 1.235' > > If you want something fancier I think you will have to do it yourself. > > Kent Kent:
Thanks for your response. That method is certainly good enough for general use. What about a case where the user needs to keep track of significant digits? As an example, assume that the following values (pulled arbitrarily from my head, I admit) are accurate to three significant digits: 253. 77.6 9.03 .0210 Using a formatting string of "%10.4f", these would be rendered as: ' 253.0000' ' 77.6000 ' 9.0300' ' 0.0210' This formatting gives the impression that all values but the last are more precise than they truly are. A scientist or statistician would prefer to see something like this: '254. ' ' 77.6 ' ' 9.03 ' ' 0.0210' Does numpy or some other math package have that capability? Thanks again. Barry [EMAIL PROTECTED] 541-302-1107 ________________________ We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor