Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Standard form

by Anonymous Monk
on Apr 20, 2005 at 13:02 UTC ( #449573=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

very newbie question sorry! I've written a script which reads numbers from a text file so far no problem as perl is clever enough to know they're numbers some of these numbers are expressed in standard form as for example 5.13E-04 always like that E - digit digit do i need to write a function to convert to a number or is there one built in i've been scouring the perl cd bookshelf and can't find one

Replies are listed 'Best First'.
Re: Standard form
by splinky (Hermit) on Apr 20, 2005 at 13:13 UTC
    Perl natively recognizes scientific notation, so you shouldn't have to do anything.
Re: Standard form
by Bukowski (Deacon) on Apr 20, 2005 at 14:19 UTC
    If you want to find the right document for how Perl handles numbers etc. you should check out "perldoc perlnumber" or look at it on-line: here

    Bukowski - aka Dan (dcs@black.hole-in-the.net)
    "Coffee for the mind, Pizza for the body, Sushi for the soul" -Userfriendly
Re: Standard form
by dorko (Prior) on Apr 20, 2005 at 13:29 UTC
    I think you can't find anything because Perl is smart enough to "Do What You Mean" (tm).
    #!/usr/bin/perl use strict; use warnings; use diagnostics; my ($number1, $number2, $number3) = <DATA>; my $number = 5.13E-04; my $other = "5.13E-04"; print "sum 1 = ", $number + $other; print "\n"; print "sum 2 = ", $number1 + $number2 + $number3; __DATA__ 5.12E-04 5.12E+04 1
    Results:
    sum 1 = 0.001026 sum 2 = 51201.000512

    Cheers,

    Brent

    -- Yeah, I'm a Delt.
Re: Standard form
by Anonymous Monk on Apr 20, 2005 at 14:19 UTC
    aye it does thanks! i thought perl would be clever enough but when my script didn't give the answers i'd been asured where right i assumed that it was the way the standard form was written actually the right numbers are wrong! thanks though

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://449573]
Approved by sweetblood
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-05-23 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?