This is due to an error in precision when you constructed the table:

use strict; use warnings; use Test::More tests => 10; use DBI; my $dbuser = shift @ARGV || 'foo'; my $dbpass = shift @ARGV || 'bar'; my $val = 1679971; my $dbh = DBI->connect ('dbi:mysql:test', $dbuser, $dbpass) or die "Conn error: $DBI::errstr"; ok ($dbh->do('CREATE TABLE foo ( bar FLOAT )'), 'Table created'); try_now ($dbh, $val); $dbh->do ('DROP TABLE foo'); ok ($dbh->do('CREATE TABLE foo ( bar FLOAT (10,0) )'), 'Table created +with right precision'); try_now ($dbh, $val); $dbh->do ('DROP TABLE foo'); $dbh->disconnect; sub try_now { my ($dbh, $val) = @_; my $out = 0; ok ($dbh->do('INSERT INTO foo VALUE (?)', undef, $val), 'Value + inserted'); ok (my $sth = $dbh->prepare ('SELECT bar FROM foo'), 'Select p +repared'); ok ($sth->execute, 'Select executed'); ($out) = $sth->fetchrow_array; is ($val, $out, "Output value $out equals input value $val"); }

Here's my result of running this:

1..10 ok 1 - Table created ok 2 - Value inserted ok 3 - Select prepared ok 4 - Select executed not ok 5 - Output value 1679970 equals input value 1679971 # Failed test 'Output value 1679970 equals input value 1679971' # at myfloat.t line 30. # got: '1679971' # expected: '1679970' ok 6 - Table created with right precision ok 7 - Value inserted ok 8 - Select prepared ok 9 - Select executed ok 10 - Output value 1679971 equals input value 1679971 # Looks like you failed 1 test of 10.

So, it's nothing to do with Perl and shows that your PHP script is telling porkies.

Update: I suggest you read all about FLOAT in MySQL and particularly the caveats about rounding, precision and exact comparison.


In reply to Re: Retrieve float number from mysql db by hippo
in thread OT: Retrieve float number from mysql db by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.