in reply to Decimal to Scientific notation
All the answers given so far are fine if there are 11* digits after the decimal point. But what if the mantissa is longer than 11 digits?:
printf "%.11e\n", 0.99982928833123; # 9.99829288331e-001
Still truncated...
And what if there are considerably fewer digits:
printf "%.11e\n", 0.999; # 9.9980000000e-001
Would the OP want all those extra zeroes?
One solution (admittedly not very elegant):
my $dec = 0.99982928833123; my $len = length( ( split /\./, $dec )[1] ); printf "%.${len}e\n", $dec; # 9.99829288331230e-001
* Well, or 12 in this case.
|
|---|