in reply to Printing with a Specific Scientific Notation Exponent

Update: ikegami++ is right: printf is needed for a more general solution.
use strict; use warnings; my $exp = -4; my $in = 5e-2; my $out = $in/10**$exp; print "$in --> ${out}e${exp}\n"; __END__ 0.05 --> 500e-4

Replies are listed 'Best First'.
Re^2: Printing with a Specific Scientific Notation Exponent
by ikegami (Patriarch) on Sep 18, 2008 at 21:14 UTC

    Not quite.

    5e-010 --> 5e-006e-4

    Use sprintf '%f' to avoid that problem.

    my $out = sprintf('%f', $in/10**$exp);