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

Well, this works for me.

use strict; use warnings; my $base=2; my $power=-12; my $number = $base * (10**$power); my $p = abs($power); my $string=sprintf("%.${p}f", $number); print $string;

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Replies are listed 'Best First'.
Re^8: help with sprintf
by graff (Chancellor) on Jun 27, 2008 at 00:16 UTC
    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 );
Re^8: help with sprintf
by lil_v (Sexton) on Jun 26, 2008 at 19:27 UTC
    thx alot!