Velocity Reviews > Perl > converting exponential format number to decimal format number

# converting exponential format number to decimal format number

Fei Liu
Guest
Posts: n/a

 12-14-2006
Hi group, is there a quick way to convert an exponential format number
to decimal format number. For example,

13.534e+10 = 1353400000

I can come up a perl function but it's not perly. Can I get some help

John Bokma
Guest
Posts: n/a

 12-14-2006
"Fei Liu" <(E-Mail Removed)> wrote:

> 13.534e+10

perl -e "print 13.534e+10"
135340000000

perl -e "my \$var = 13.534e+10; print length \$var"
12

So at least here (WinXP+ActiveState) Perl does this internally.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/

usenet@DavidFilmer.com
Guest
Posts: n/a

 12-14-2006
Fei Liu wrote:
> Hi group, is there a quick way to convert an exponential format number
> to decimal format number. For example,
>
> 13.534e+10 = 1353400000

print 13.534e+10;

#prints 135340000000

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

Fei Liu
Guest
Posts: n/a

 12-14-2006

John Bokma wrote:
> "Fei Liu" <(E-Mail Removed)> wrote:
>
> > 13.534e+10

>
> perl -e "print 13.534e+10"
> 135340000000
>
> perl -e "my \$var = 13.534e+10; print length \$var"
> 12
>
> So at least here (WinXP+ActiveState) Perl does this internally.
>

Thanks for your input, but try 13.534e+26, you will find perl prints
13.534e+26. It's part of the code
where it reads this number from a file and the output needs to be
converted to decimal format for another application (say myapp) to use.
Unfortunately, myapp only understands decimal format number.

J. Gleixner
Guest
Posts: n/a

 12-14-2006
Fei Liu wrote:
> John Bokma wrote:
>> "Fei Liu" <(E-Mail Removed)> wrote:
>>
>>> 13.534e+10

>> perl -e "print 13.534e+10"
>> 135340000000
>>
>> perl -e "my \$var = 13.534e+10; print length \$var"
>> 12
>>
>> So at least here (WinXP+ActiveState) Perl does this internally.
>>

>
> Thanks for your input, but try 13.534e+26, you will find perl prints
> 13.534e+26.

I find it prints 1.3534e+27

Look at: perldoc bigint

usenet@DavidFilmer.com
Guest
Posts: n/a

 12-14-2006
Fei Liu wrote:
> Thanks for your input, but try 13.534e+26, you will find perl prints
> 13.534e+26. It's part of the code

use Math::BigInt;
my \$int = Math::BigInt->new('13.534e+26');
print \$int->as_int();

#prints 1353400000000000000000000000

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

xhoster@gmail.com
Guest
Posts: n/a

 12-14-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Fei Liu wrote:
> > Thanks for your input, but try 13.534e+26, you will find perl prints
> > 13.534e+26. It's part of the code

>
> use Math::BigInt;
> my \$int = Math::BigInt->new('13.534e+26');
> print \$int->as_int();

Or, if you don't mind there being some 9's way out at the end,

printf "%f", 13.534e26

Xho

--
Usenet Newsgroup Service \$9.95/Month 30GB

usenet@DavidFilmer.com
Guest
Posts: n/a

 12-14-2006
(E-Mail Removed) wrote:
> my \$int = Math::BigInt->new('13.534e+26');
> print \$int->as_int();

Or, if you are just doing the one conversion and don't need to retain
the constructor:

print Math::BigInt->new('13.534e+26')->as_int();

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

John Bokma
Guest
Posts: n/a

 12-14-2006
"Fei Liu" <(E-Mail Removed)> wrote:

> John Bokma wrote:
>> "Fei Liu" <(E-Mail Removed)> wrote:
>>
>> > 13.534e+10

>>
>> perl -e "print 13.534e+10"
>> 135340000000
>>
>> perl -e "my \$var = 13.534e+10; print length \$var"
>> 12
>>
>> So at least here (WinXP+ActiveState) Perl does this internally.
>>

>
> Thanks for your input, but try 13.534e+26

So, you gave a bad example. Always make your problem description as
complete as possible and provide examples that show your specific problem.
This way people can help you better, and you don't waste a lot of time of
other people.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/

Dr.Ruud
Guest
Posts: n/a

 12-14-2006
Fei Liu schreef:

> Hi group, is there a quick way to convert an exponential format
> number to decimal format number. For example,
>
> 13.534e+10 = 1353400000
>
> I can come up a perl function but it's not perly.

This works in a limited way:

perl -we 'printf "%.0f\n", q/9.64e+21/'
9640000000000000000000

--
Affijn, Ruud

"Gewoon is een tijger."