error with float field

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
maxchenjun
Posts: 8
Joined: Tue 13 Nov 2007 10:26

error with float field

Post by maxchenjun » Sun 23 Dec 2007 01:08

Delphi 7.0
mydac 5.20.0.12 Pro.

SQL script:

Code: Select all

CREATE TABLE IF NOT EXISTS `mydac` (
  `id` int(11) NOT NULL auto_increment,
  `price` float NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;

--
-- Daten für Tabelle `mydac`
--

INSERT INTO `mydac` (`id`, `price`) VALUES
(1, 23),
(2, 49.49),
(3, 100.01),
(4, 34.5);
All these values are shown not correctly after click on a refresh button, whose on click event is this:

Code: Select all

MyTable1.SQL.Text:= 'select * from '+MyTable1.TableName;
MyTable1.Prepare;
MyTable1.Execute;
And float values are shown as 49.4900016784668 and so on.

Is this a bug or how can I solve this problem? Thanks in advance.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 24 Dec 2007 10:49

Described problem is a peculiarity of handling float fields by MySQL. To solve the problem, change the field type to DOUBLE or DECIMAL(11, 2).
Also, the result will be correct if you do not call the MyTable1.Prepare method.

Post Reply