I think you need to roll your own for this. The following will get you started:
use strict; use warnings; my $num = 0.05; my $num_string = sprintf("%e", $num); print "$num_string\n"; my($mantissa, $exponent) = split /e/, $num_string; my $new_exp = $exponent + 4; my $new_mantissa = $mantissa * 10**$new_exp; print $new_mantissa, "e-04\n"; __DATA__ 5.000000e-02 500e-04
The right way to do this, of course, is in a subroutine, where you pass in your number along with the desired fixed exponent ('-4' in your example). In that case you need to change the '4' to a variable in the $new_exp calculation. You may also want to use sprintf to format the mantissa for your output (maybe you want 500.0 instead of just 500, for example).

Updated: You really need

$new_exp = $exponent - $fixed_exponent;

if you want to allow for an arbitrary fixed exponent. My example above applies only to negative values of the fixed exponent.

Never mind. I see now at the end of the OP that ysth supplied a better answer. :-)


In reply to Re: Printing with a Specific Scientific Notation Exponent by broomduster
in thread Printing with a Specific Scientific Notation Exponent by behindalens

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.