Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to use sprintf in one command to turn 0.30 into 30%?

Thanks,
Me

Replies are listed 'Best First'.
Re: percentage and sprintf
by hippo (Archbishop) on May 14, 2013 at 22:31 UTC

    Sure:

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

      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;