print int(10e5);
print
int(-10e5);
This doesn't appear to work, though, if formatted as 10e-5, so you'd need to create a sub something like:
I think you may be making it too hard. Remember this is Perl.
#!perl -w
while ( 1 ) {
printf "Plase enter number:
";
chomp(my $MyAns = <STDIN>);
last if ( $MyAns =~ /^\s*(qu|en)/i );
my $MyNbr = sprintf
"%e",
$MyAns; #1#
$MyNbr =~
/^(\d+)/;
#1#
my $MyDigits =
$1; #1#
printf "%s
%s\n",
$MyNbr,
$MyDigits;
}
output:
Please enter number: 105
1.050000e+002 1
Please enter number:
.00456
4.560000e-003 4
Even mine seems harder than it should be, but it is a start and only the #1# are needed to get the digit you desire.
Wags ;)
sub exp2int
{
$_ = shift;
my ($num,$exp) =
split(/e/,$_);
if ($exp > 0)
{
$num *= 10;
for (my $i = 1; $i <
$exp; $i++)
{
$num *= 10;
}
}
elsif ($exp <
0)
{
$num *= -10;
for (my $i = -1; $i >
$exp; $i--)
{
$num *= 10;
}
}
return($num);
}
#here's the inverse
sub int2exp
{
my $num = shift;
my
$count;
while(($num < -10)
|| ($num > 10))
{
$num = $num / 10;
$count++;
}
$new =
"${num}e${count}";
return($new);
}
# end
Of course, there may be a really simple answer to this puzzle.
HTH,
Pete
> -----Original Message-----
>
From: Mehta, Perdeep [mailto:[EMAIL PROTECTED]]
> Sent: Friday, February 27, 2004 12:36 PM
> To: [EMAIL PROTECTED]
> Subject: [Perl-unix-users] conversion between exponential and
> corresponding integer value
>
>
> Dear Perl
Gurus,
>
> I need help to
convert an exponential value such as 10e-5 to
> its
integer value and vice versa in a perl script.
>
> Thanks in advance for any help.
> perdeep
>
>
Perdeep K. Mehta
> Hartwell Center for Bioinformatics
& Biotechnology
> St. Jude Children's Research
Hospital
> Memphis, TN 38105-2794
> Tel: 901-495 3774
> http://www.hartwellcenter.org
>
>
>
> _______________________________________________
> Perl-Unix-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************
_______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs