> -----Original Message-----
> From: Dan Fish [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 07, 2002 8:33 AM
> To: [EMAIL PROTECTED]
> Subject: Format of %e output
> 
> 
> I've got this *really ancient* program (for which I naturally 
> don't have the
> source :-) that  parses reports and expects floating point 
> numbers to be in
> the %e format with 2 exponent digits (I.E. 3.045E+06).
> 
> I'm trying to feed it some output of my own from a perl 
> script, but perl
> seems insistent on  supplying %e numbers with 3 exponent digits (I.E.
> 3.045E+006) and the program parser complains.
> 
> Is there a way to force perl to output using the %e format with only 2
> exponent digits??

'perldoc -f sprintf' contains the following statement:

   Note that the number of exponent digits in the scientific
   notation by "%e", "%E", "%g" and "%G" for numbers with the
   modulus of the exponent less than 100 is system-dependent: it
   may be three or less (zero-padded as necessary). In other words,
   1.23 times ten to the 99th may be either "1.23e99" or
   "1.23e099".

You can do something like the following to get the format you
want:

   $n = 1_234_567_890;
   ($m, $e) = split(/e/, sprintf('%e', $n));
   $e = sprintf('%+03d', $e);
   print "${m}E${e}\n";

Output: 1.234568E+09

I'm just splitting off the exponent and reformatting it.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to