in reply to percentage and sprintf

Sure:

my $foo = 0.30; my $bar = sprintf "%2.2i%%", $foo * 100;

Replies are listed 'Best First'.
Re^2: percentage and sprintf
by ambrus (Abbot) on May 15, 2013 at 09:44 UTC

    That works, but I'd recommend this instead so that the percentage is rounded to an integer rather than truncated.

    my $bar = sprintf "%2.0f%%", $foo * 100;