in reply to simple!!

How about:

printf("%e",122.34);

or if you want it exactly the way you said:
$_=sprintf("%#1.4e",122.34); s/e([+-])(.*)/"e($1".int($2).")"/e; print;


/brother t0mas

Replies are listed 'Best First'.
RE: RE: simple!!
by KM (Priest) on Aug 19, 2000 at 00:44 UTC
    Just to take it farther... to undo this, you could:

    s/([\.\d]+)e\(?([-+]?\d+)\)?/$1*10**$2/egi;

    I would rather have the notation given as 1.2234e+2, simply because Perl sees that as a number. By that I mean if you:

    my $foo = 1.2234e(+2);

    Perl will complain. If you do the following, it won't:

    my $foo = 1.2234e+2;

    The above RE should handle both cases. This is fun though..

    $_=sprintf("%#1.4e",122.34); print; s/([\.\d]+)e\(?([-+]?\d+)\)?/$1*10**$2/egi; print $/; print;

    Cheers,
    KM

      A very nice undo regexp there...

      I agree with you KM that 1.2234e+2 is a better format for keeping and operations, but for printing (as I believe vnpandey wanted) I rather use the format that pays my bills :)


      /brother t0mas