Newbie quesion: Scientific notation

Discussion in 'Perl Misc' started by mdfoster44@netscape.net, Feb 1, 2005.

  1. Guest

    Hi,

    I'm trying to upload some data into a MySQL database.

    Could someone please advise me how I handle scientific notation?

    What I have sofar:

    -------
    The data (pt, x)

    P1 4.50015068000000D-004
    -------

    My regex expressions, I've been experimenting with:

    regex1: P\d+\s+(-?([0-9]+(\.[0-9]*)?|\.[0-9]+))/)
    does not catch the scientific notation

    regex2: P\d+\s+([+-]?(\d+(\.\d*)?|\.\d+)([eEdD][+-]?\d+))/)
    does catch the scientific notation. I then say,
    $number = $1;

    -------
    # Insert data
    $dbh->do("INSERT INTO data(x) VALUES (?)",undef, $number);
    -------

    How do I upload the number to the database? If I do it as above it is
    incorrect.

    Thanks your help.

    Martin.
     
    , Feb 1, 2005
    #1
    1. Advertising

  2. Anno Siegel Guest

    <> wrote in comp.lang.perl.misc:
    > Hi,
    >
    > I'm trying to upload some data into a MySQL database.
    >
    > Could someone please advise me how I handle scientific notation?
    >
    > What I have sofar:
    >
    > -------
    > The data (pt, x)
    >
    > P1 4.50015068000000D-004
    > -------
    >
    > My regex expressions, I've been experimenting with:
    >
    > regex1: P\d+\s+(-?([0-9]+(\.[0-9]*)?|\.[0-9]+))/)

    ^ ^^
    Are these supposed to be regex delimiters?

    > does not catch the scientific notation


    Of course not. What makes you think it would?

    > regex2: P\d+\s+([+-]?(\d+(\.\d*)?|\.\d+)([eEdD][+-]?\d+))/)
    > does catch the scientific notation. I then say,
    > $number = $1;


    For matching numbers with regular expressions, see perldoc -q "is a number".
    Follow the pointers you find there.

    > -------
    > # Insert data
    > $dbh->do("INSERT INTO data(x) VALUES (?)",undef, $number);
    > -------
    >
    > How do I upload the number to the database? If I do it as above it is
    > incorrect.


    Incorrect how? Is the data rejected by the database? Is it accepted
    but not the values you expect it to be? Be specific.

    Anno
     
    Anno Siegel, Feb 1, 2005
    #2
    1. Advertising

  3. Guest

    Re: Newbie quesion: Scientific notation

    Anno Siegel wrote:
    > <> wrote in comp.lang.perl.misc:
    > > Hi,
    > >
    > > I'm trying to upload some data into a MySQL database.
    > >
    > > Could someone please advise me how I handle scientific notation?
    > >
    > > What I have sofar:
    > >
    > > -------
    > > The data (pt, x)
    > >
    > > P1 4.50015068000000D-004
    > > -------
    > >
    > > My regex expressions, I've been experimenting with:
    > >
    > > regex1: P\d+\s+(-?([0-9]+(\.[0-9]*)?|\.[0-9]+))/)

    > ^ ^^
    > Are these supposed to be regex delimiters?
    >
    > > does not catch the scientific notation

    >
    > Of course not. What makes you think it would?
    >
    > > regex2: P\d+\s+([+-]?(\d+(\.\d*)?|\.\d+)([eEdD][+-]?\d+))/)
    > > does catch the scientific notation. I then say,
    > > $number = $1;

    >
    > For matching numbers with regular expressions, see perldoc -q "is a

    number".
    > Follow the pointers you find there.

    Ah, this helps alot thanks! I just didn't find that before.
    >
    > > -------
    > > # Insert data
    > > $dbh->do("INSERT INTO data(x) VALUES (?)",undef, $number);
    > > -------
    > >
    > > How do I upload the number to the database? If I do it as above it

    is
    > > incorrect.

    >
    > Incorrect how? Is the data rejected by the database? Is it accepted
    > but not the values you expect it to be? Be specific.

    Well the number it uploads is not the float, in this case double, that
    I want it to be. I'll need to do a strtod.
    >
    > Anno

    Martin.
     
    , Feb 2, 2005
    #3
  4. Anno Siegel Guest

    Re: Newbie quesion: Scientific notation

    <> wrote in comp.lang.perl.misc:
    >
    > Anno Siegel wrote:
    > > <> wrote in comp.lang.perl.misc:


    > > > Hi,
    > > > I'm trying to upload some data into a MySQL database.


    [...]

    > > > How do I upload the number to the database? If I do it as above it

    > is
    > > > incorrect.

    > >
    > > Incorrect how? Is the data rejected by the database? Is it accepted
    > > but not the values you expect it to be? Be specific.

    >
    > Well the number it uploads is not the float, in this case double, that
    > I want it to be.


    Please be specific! Telling us it is not what you want it to be helps
    no-one.

    What is the data your code offers to the DB? How does the DB receive it?
    What does the DB give back, if anything? That's the kind of info we
    need.

    >I'll need to do a strtod.


    No, you need it to be what the documentation of your database interface
    wants it to be. I have no idea what it expects, but I doubt it's described
    as "a strtod":

    Anno
     
    Anno Siegel, Feb 2, 2005
    #4
  5. Guest

    Re: Newbie quesion: Scientific notation

    Anno Siegel wrote:
    > <> wrote in comp.lang.perl.misc:
    > >
    > > Anno Siegel wrote:
    > > > <> wrote in comp.lang.perl.misc:

    >
    > > > > Hi,
    > > > > I'm trying to upload some data into a MySQL database.

    >
    > [...]
    >
    > > > > How do I upload the number to the database? If I do it as

    above it
    > > is
    > > > > incorrect.
    > > >
    > > > Incorrect how? Is the data rejected by the database? Is it

    accepted
    > > > but not the values you expect it to be? Be specific.

    > >
    > > Well the number it uploads is not the float, in this case double,

    that
    > > I want it to be.

    >
    > Please be specific! Telling us it is not what you want it to be

    helps
    > no-one.
    >
    > What is the data your code offers to the DB? How does the DB receive

    it?
    > What does the DB give back, if anything? That's the kind of info we
    > need.


    The data point
    -------
    The data (pt, x)

    P1 4.50015068000000D-004
    -------
    >From the regex I have sofar,

    $number = 4.50015068000000D-004

    This is now just a string, I've been incorrectly feeding this to the
    database,
    where it is expecting a double( double(20,6)).
    Which explains why the DB returns
    "4.500151"

    I need to convert the string stored in $number to a double number.
    string to double (strtod). So from perldoc -q "is a number", I've
    used:

    use POSIX qw(strtod);
    my $double = strtod($number);

    However, the strtod function doesn't like the "D" in my number, ie
    4.50015068000000D-004 needs to be 4.50015068000000e-004. So I do a
    quick
    substitution.
    Thanks for your pointer, sorry for my being vague.

    Martin.
     
    , Feb 2, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ville Ahonen

    No scientific notation?

    Ville Ahonen, Oct 19, 2004, in forum: C++
    Replies:
    2
    Views:
    450
    Mike Wahler
    Oct 19, 2004
  2. Dustan

    Scientific Notation

    Dustan, Dec 4, 2005, in forum: Python
    Replies:
    7
    Views:
    13,465
    Dustan
    Dec 4, 2005
  3. grinder

    reguarding scientific notation

    grinder, Aug 28, 2006, in forum: C Programming
    Replies:
    7
    Views:
    460
    Knemon
    Aug 29, 2006
  4. asdf
    Replies:
    2
    Views:
    554
    Rolf Magnus
    Oct 21, 2006
  5. N1GHTS

    Scientific Notation Conversion

    N1GHTS, Feb 20, 2008, in forum: C Programming
    Replies:
    1
    Views:
    576
    N1GHTS
    Feb 20, 2008
Loading...

Share This Page