Quoth Daniel Cutter <_I S_DE>:
> I thought that printf would allways right justify numbers, unless told
> to do differently (with '-'). perlfunc doesn't tell.
>
> #!perl
> use strict;
> use warnings;
> printf("%2.1f\n", 12.3);
> printf("%2.1f\n", 4.5);
> printf("%02.1f\n", 6.7);
The number before the . is the minimum total field width, not the number
of places before the decimal (yes, I think this is confusing too, but
it's more consistent with %3.5s). So you want
printf("%4.1f\n", 12.3);
printf("%4.1f\n", 4.5);
printf("%04.1f\n", 6.7);
Ben
|