in reply to Re^7: help with sprintf
in thread help with sprintf

You can also supply the field width as one of the args that you put after the format string, by putting "*" in the format where that numeric should go:
my $string = sprintf( "%.*f", $p, $number );