Skip Menu |
 

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 13363
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: agustinus [...] telkom.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: bug in float data type
Download (untitled) / with headers
text/plain 894b
Name: DBD-mysql Version: 2.9007 Author: Patrick Galbraith (patg@mysql.com) Title: DBD-mysql Abstract: A MySQL driver for the Perl5 Database Interface (DBI) InstDate: 19:34:06 2005 Location: http://ppm.ActiveState.com/PPM/ppmserver-5.8-windows.plex?urn:/PPM/Server/SQL Prerequisites: 1. DBI 0.0 Available Platforms: 1. MSWin32-x86-multi-thread-5.8 Perl version : perl, v5.8.6 built for MSWin32-x86-multi-thread OS : MS Windows 2000 profesional I create table as following : create table test ( floatnum float(13,3) ); and run some code as following : $query = qq| INSERT INTO test (floatnum) VALUES (1000000.123 ) |; $sth = $dbh->prepare($query); $sth->execute(); the result is : Show quoted text
mysql> select * from test;
+-------------+ | floatnum | +-------------+ | 1000000.125 | +-------------+ The result is ok for small value. The deviation is bigger for bigger number.
This is a MySQL server bug, and not a DBD::mysql bug: Show quoted text
mysql> create table test ( floatnum float(13,3) );
Query OK, 0 rows affected (0.02 sec) Show quoted text
mysql> INSERT INTO test (floatnum) VALUES (1000000.123 );
Query OK, 1 row affected (0.01 sec) Show quoted text
mysql> select * from test;
+-------------+ | floatnum | +-------------+ | 1000000.125 | +-------------+ 1 row in set (0.02 sec) This is expected behaviour of float: "if you insert (1000000.123) in a column defined as float(13,4) you get 1000000.1250? that's still okay. you can't handle every possible float value in 4 bytes, so automatic change to the nearest equivalent sometimes happens, and is accepted. it's not an sql issue, it's ieee 754 floating-point storage." Try: Show quoted text
mysql> create table test ( floatnum decimal(13,3) );
Query OK, 0 rows affected (0.00 sec) Show quoted text
mysql> INSERT INTO test (floatnum) VALUES (1000000.123 );
Query OK, 1 row affected (0.00 sec) Show quoted text
mysql> select * from test;
+-------------+ | floatnum | +-------------+ | 1000000.123 | +-------------+ 1 row in set (0.01 sec)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.