Re: padding numbers with spaces

2001-07-06 Thread Michael Fowler
On Fri, Jul 06, 2001 at 01:06:00PM -0400, David Gilden wrote: > I am trying with out much success to get the following to happen: > > Using this statement: > > $average = sprintf ("%2.1f", ($total / $scores)); > > I want my numbers to line up like so: [note the left padding with the ' '] > >

Re: padding numbers with spaces

2001-07-06 Thread Ken
Try %5.1f in your sprintf The first number is the width of the field, in this case your format, @, is specifying 5 wide. Alernatively you could make your format @##.# and get rid of the sprintf $average = $total / $scores; - Original Message - From: "David Gilden" <[EMAIL PROTECTED

Re: padding numbers with spaces

2001-07-06 Thread Recelon -
Try adding the second and third line below: $average = sprintf ("%2.1f", ($total / $scores)); #original line $average = ' ' x (2 - int(log($average)/log(10))) . $average; $average =~ s/\.0+//; The second line effectively takes the log base 10 of the average, and adds additional whitespace to p