... manipulate the formatting of a number ... %.{$var}f does the trick.
Another way is the printf * format specifier:
c:\@Work\Perl\monks>perl -wMstrict -le
"my $p = 30;
my $n = 1.111111111111111111111111111111;
;;
printf '%0.*f', $p, $n;
"
1.111111111111111200000000000000
See
sprintf for a discussion of all format specifiers.
Update: Actually, %.{$var}f doesn't do any trick except to produce an "Invalid conversion in printf..." warning. But the syntax is correct in the OPed example code:
printf( "%.${dig}f", $num );
Give a man a fish: <%-{-{-{-<