# Perl and scientific notation

This topic is 3418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a perl script that reads in some numbers, which are in scientific notation such as: 0.0100E+01 However, I need to do some math on it. What is the best way to get it into a floating point format so math can be done? I've searched Google, but I haven't really found anything regarding this.

##### Share on other sites
A quick and dirty solution is to parse it, char by char, using a state machine.
I've already a chart for this parsing a string containing a floating point number into its floating point representation, would this help?

##### Share on other sites
Nah, I think I have the parsing thing cased. I actually have this thread as reference FWIW.

I was just hoping I didn't have to manually parse the number...I like to try to limit the amount of wheels I reinvent :)

I appreciate the offer!!

##### Share on other sites
I know that my numbers will always be legal scientific notation. Is it fair game to do this:

$input =~ s/[Ee]/\*10\*\*/; #replace E or e with *10**my$parsed = eval $input;print "$parsed\n";

I feel dirty, but it seems to work!

##### Share on other sites
Admittedly it's been a decade since I touched perl, but can't you just read it normally and use it normally? I'm pretty sure scanf and its ilk, of which Perl is descended, operate just fine on scientific notation.

##### Share on other sites
Quote:
 Original post by SneftelAdmittedly it's been a decade since I touched perl, but can't you just read it normally and use it normally? I'm pretty sure scanf and its ilk, of which Perl is descended, operate just fine on scientific notation.

And it does too...very odd, I swear it was crashing on the scientific notation I was feeding it as an example....

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009458
• ### Who's Online (See full list)

There are no registered users currently online

×