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

If $power is negative, you should define another var equal to -$power.

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

Replies are listed 'Best First'.
Re^6: help with sprintf
by lil_v (Sexton) on Jun 26, 2008 at 19:04 UTC
    yeah thats why i updated my post... even then, the numbers after 6 decimal places dont show.

      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."

        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 );
        thx alot!